From: Kenneth M. Lin on 27 Mar 2010 02:10 I know that in Unix I can use FILENAME PIPE command then use DATA STEP to read in results of a system command. For example, filename abc PIPE "ls -al"; data work.xyz; infile abc; input ...; call symput...; ; However, is there an elegant way to assign an one-line outcome of an Unix command into a SAS macro variable? I can use %sysexec to execute the Unix command, direct it into a text file, then read it in using DATA STEP but isn't there a direct way to pass the output to SAS?
From: xlr82sas on 27 Mar 2010 03:23 On Mar 26, 11:10 pm, "Kenneth M. Lin" <kenneth_m_...(a)sbcglobal.net> wrote: > I know that in Unix I can use FILENAME PIPE command then use DATA STEP to > read in results of a system command. For example, > > filename abc PIPE "ls -al"; > data work.xyz; > infile abc; > input ...; > call symput...; > ; > > However, is there an elegant way to assign an one-line outcome of an Unix > command into a SAS macro variable? I can use %sysexec to execute the Unix > command, direct it into a text file, then read it in using DATA STEP but > isn't there a direct way to pass the output to SAS? Hi, You can set up a pipe in the macro language, not very elegant. I don't have SAS right now so this is from memory. There are probably many syntax errors. UNIX example %let rc=%sysfunc(filename(fname,echo getthis ,pipe)); %let fop=%sysfunc(fopen(&fname,,,i)); %let rc=%sysfunc(fget(&fop,txt)); %let rc=%sysfunc(fclose(&fop)); %let rc=%sysfunc(fclose(&fop)); Macro variable Txt should have getthis I have several examples of reading files and SAS datasets on my site http://homepage.mac.com/magdelina/.Public/utl.html utl_tipweb see /* T002510 READING A SAS DATASET AND A FLATILE USIN THE MACRO LANGUAGE Here is an excerpt /* create a sample file fo input to macro read code */ filename tmp temp; data _null_; set sashelp.class; file tmp; put @1 name @10 age @20 age; run; /* read the file in the macro language */ %macro readfile(tmp); %let fid=%sysfunc(fopen(tmp,s)); %do %while(%sysfunc(fread(&fid)) EQ 0); %let rc=%sysfunc(fget(&fid,str,200)); %put &str; %end; %let rc=%sysfunc(fclose(&fid)); %mend readfile; %readfile;
From: MichelleZ on 27 Mar 2010 08:28 On Mar 27, 1:10 am, "Kenneth M. Lin" <kenneth_m_...(a)sbcglobal.net> wrote: > I know that in Unix I can use FILENAME PIPE command then use DATA STEP to > read in results of a system command. For example, > > filename abc PIPE "ls -al"; > data work.xyz; > infile abc; > input ...; > call symput...; > ; > > However, is there an elegant way to assign an one-line outcome of an Unix > command into a SAS macro variable? I can use %sysexec to execute the Unix > command, direct it into a text file, then read it in using DATA STEP but > isn't there a direct way to pass the output to SAS? Kenneth, If you mean you want to do some task once for each outcome of the Unix command.... filename abc PIPE "ls -al"; data work.xyz; infile abc; input ...; run; proc sql noprint; select count(*) into :noofresults from xyz; ; quit; %macro mymacro; %do k = 1 %to &noofresults; data _null_; set xyz; if _n_ = &k; call symput("variable&k.",input); run; data &&variable&k; set ...; run; %end; %mend; %mymacro;
From: RolandRB on 29 Mar 2010 05:53 On Mar 27, 8:10 am, "Kenneth M. Lin" <kenneth_m_...(a)sbcglobal.net> wrote: > I know that in Unix I can use FILENAME PIPE command then use DATA STEP to > read in results of a system command. For example, > > filename abc PIPE "ls -al"; > data work.xyz; > infile abc; > input ...; > call symput...; > ; > > However, is there an elegant way to assign an one-line outcome of an Unix > command into a SAS macro variable? I can use %sysexec to execute the Unix > command, direct it into a text file, then read it in using DATA STEP but > isn't there a direct way to pass the output to SAS? %let dsid=%sysfunc(open(&ds,is)); %if &dsid EQ 0 %then %do; %put ERROR: (varnum) Dataset &ds not opened due to the following reason:; %put %sysfunc(sysmsg()); %end;
|
Pages: 1 Prev: PROC COMPARE checking unique records irrespective of position Next: Current title |