Unzipping files in SAS - sas

I was wondering if you could help me understand a piece of SAS code that I found to unzip files from SAS in UNIX? I found this code to zip the file, but I am unsure how to unzip the file.
/*x gunzip /sasdata3/MI/projects/hedis_vendor/production/inovprev/data/download/M201803/Process/unprocessed/invbsca_aba18_detail_fcr_r12_with_ce_20180330_summary_detail_dongmei_march_rolling12_preview_3_31_2018_4_18_26_pm.zip.gz;
DATA _NULL_;
tstring='gzip /sasdata3/MI/projects/hedis_vendor/production/inovprev/data/download/M201803/Process/unprocessed/invbsca_aba18_detail_fcr_r12_with_ce_20180330_summary_detail_dongmei_march_rolling12_preview_3_31_2018_4_18_26_pm.zip;';
rc = SYSTEM(tstring);
RUN; */;

I hope you find my explanation below useful:
The code you sent is commented out. In SAS any thing between /* some code/comments */ will be treated as comments.
It looks like your environment have X command enabled in SAS; this means you can run Operating System commands via SAS code.
DATA _NULL_; /* Empty data step which will not create any table*/
tstring=' some OS command like gzip or gunzip'; /*The OS cmd is places here*/
rc = SYSTEM(tstring); /*SAS invokes the OS and executes the command saved in the variable tstring*/
RUN;
This code have to commands which you can place either of them in the tstring='';
Zip:
gzip /sasdata3/MI/projects/hedis_vendor/production/inovprev/data/download/M201803/Process/unprocessed/invbsca_aba18_detail_fcr_r12_with_ce_20180330_summary_detail_dongmei_march_rolling12_preview_3_31_2018_4_18_26_pm.zip;
Unzip:
gunzip /sasdata3/MI/projects/hedis_vendor/production/inovprev/data/download/M201803/Process/unprocessed/invbsca_aba18_detail_fcr_r12_with_ce_20180330_summary_detail_dongmei_march_rolling12_preview_3_31_2018_4_18_26_pm.zip.gz;
gzip & guzip examples

Related

Get the filename and filepath of the code running

I need to get the current running SAS program's name and file path into local variables. I accomplished that using the SAS_EXECFILEPATH and SAS_EXECFILEPATH commands. I ran this through windows SAS and it worked.
But when i tried to run this on the server in batch mode, it failed. I then tried the &_SASPROGRAMFILE parameter, which ran fine on SAS EG, but fails when I trigger it on the server in batch mode.
Is there a possible way to accomplish this in batch mode on the server?
You might be looking for %sysfunc(getoption(sysin)) (Usage Note 24301: How to retrieve the program name that is currently running in batch mode or interactively), if you start the program with sas -sysin path/to/file.sas.
I know this is delayed but you could generate a macro that calls on the right code depending on if you are running the program in the editor or in batch mode. Art Carpenter created a great macro that solves this issue.
%macro ExecPrg;
%if %sysfunc(getoption(sysin)) ne %str() %then %do;
/* Batch Execution */
%sysfunc(getoption(sysin))
%end;
%else %do;
/* Interactive Execution */
%sysget(SAS_EXECFILEPATH)
%end;
%mend execprg;

Can you write to the sas log to indicate where a current script is, i.e. the line number for example?

I want the log to be updated mid script so I know how much of the program has completed. I know about the 'put' command but this only seems to work in the final printed '.log' file after I have recieved my notifcation as either "Exit 2","Exit 1" or "Done".
In batch mode, the log is written to as the process runs. There is a buffering mechanism that means you cannot follow in perfect real time, but for big jobs it is close. Assuming (based on your command) you are on a Unix/Linix system:
tail -f blah.log
Will output the log as it is written to your terminal.
As Reeza mentioned in the comments, your other option is to write to a separate file during the run.
filename status "~/status.log";
data _null_;
file status ;
now = datetime();
put "Start at " now datetime.;
run;
<other stuff>
data _null_;
file status mod;
now = datetime();
put "I'm here at at " now datetime.;
run;
...
You can then use the same tail -f ~/status.log command to follow that file and see where processing has passed.

Define a function remotely using PROC FCMP in SAS

I've just learned PROC FCMP from this page:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a003181727.htm
The function works fine locally, so I wonder if I can use this proc remotely. In my point of view, as long as I change the output library for this function, it could be used in remote server. Here's my code:
proc fcmp outlib=rwork.funcs.trial;
function study_day2(intervention_date, event_date);
n = event_date - intervention_date;
if n >= 0 then
n = n + 1;
return (n);
endsub;
options cmplib=rwork.funcs;
run;
rsubmit;
data _null_;
start = '15Feb2008'd;
today = '27Mar2008'd;
sd = study_day2(start, today);
put sd=;
run;
endrsubmit;
For the 1st section, I get a notice that the function has been saved in the RWORK library:
NOTE: Function study_day2 saved to rwork.funcs.trial.
However after running the 2nd section, I get this error:
ERROR 68-185: The function STUDY_DAY2 is unknown, or cannot be
accessed.
Is there a way to fix this issue? Thanks!
Assuming you want to program this way (compile the function on your local machine and run it remotely), and you have a machine connected over SAS/CONNECT that is the same operating system and bitness (64/32 bit) as your local machine, you need to run options cmplib=rwork.funcs; in your rsubmit (except you likely need to change it, assuming rwork refers to your remote work directory, to options cmplib=work.funcs;).
rsubmit;
options cmplib=work.funcs;
data _null_;
start = '15Feb2008'd;
today = '27Mar2008'd;
sd = study_day2(start, today);
put sd=;
run;
endrsubmit;
That option isn't for proc fcmp, as you seem to think based on where you located it. It is telling SAS where to look when using the function. (The outlib option in proc fcmp is what is needed to store it there.)
If your remote server is a different OS or bitness than your local machine, you can't do this, and would need to put the entire section of code in the rsubmit.

SAS Apparent symbolic reference PWD not resolved

I have SAS code that reads my password from an external .txtfile and establishes connection with odbc . When i run the following code in SAS, it works fine
filename pw "C:/xxxx";
data _NULL_ ;
infile pw ;
input pw : $50. ;
call symputx('pwd',pwd);
run;
libname xxx odbc user=myUser password=&pwd. dsn=myDsn schema=mySchema;
proc sql;
connect to xxx(dsn=myDsn user=myUser password=&pwd.);
However when I create a batch file to run it from Windows task scheduler or run it from SAS Enterprise Guide I get Apparent symbolic reference PWD not resolved
Why is this happening ? How to deal with this issue ?
Because your call symputx is not correctly defining it, at least based on the code you pasted.
data _NULL_ ;
infile pw ;
input pw : $50. ;
call symputx('pwd',pw);
run;
That would be the correct syntax (or change the input statement to read pwd). Look at your datastep's log, it should have a warning pwd was uninitialized.
If you pasted the code properly, I would still look to your data step's log, and see if any rows were processed. mjsqu may be correct in that you may not have visibility to the directory (if this is on a server and you're not accessing a server-visible directory), or some other issue may present as a result of you being in a different environment.
You have a typo. My guess is that your original variable was named pwd and you tested your code and it ran fine and then you renamed it. If you close your sas session and try rerunning it I bet it fails.
Try changing to this:
filename pw "C:/xxxx";
data _NULL_ ;
infile pw ;
input pw : $50. ;
call symputx('pwd',pw);
run;

X command not working to redirect output to file

When I am submitting the following lines in cmd ,it returns the expected output by making a csv file.
C:\>Tasklist /FO CSV > C:\SomeFolder\Task.csv
However When I submit the same lines using X command in SAS, it just runs and produce no output file or error in log. I am able to run other X commands successfully
X "Tasklist /FO CSV > C:\SomeFolder\Task.csv";
I tried using SYSTASK as well but even that fails to create the csv file, am I missing something?
Thanks to the power of Printscreen and my reflex training playing Starcraft as a child, I managed to grab the error message.
ERROR: Invalid argument/option: '>'
The issue is that X isn't really a command line; it's a single command interface. You can't redirect output in quite the same way.
You have two options. If you're just doing this for the purpose of reading this back into SAS, you should use a pipe to read it in.
filename tasks pipe "tasklist /FO CSV";
data mytasks;
infile tasks lrecl=1500 dlm=',' truncover dsd firstobs=2;
length image $50;
input
Image $
PID $
Session $
SessionNo $
MemUse $
;
run;
Otherwise, you can write a .bat file and execute that via x.
filename bat "c:\temp\task.bat";
data _null_;
file bat;
put "Tasklist /FO CSV > c:\temp\Task.csv";
run;
x "c:\temp\task.bat";