DATA Step, Macro, Functions and more

Else statement in proc import macro

Reply
Regular Contributor
Posts: 178

Else statement in proc import macro

%let DorsHHFPath =/dorsshare/HHFit;

%put &DorsHHFPath;

 

 

 

%Let StateList=ga il in ky md mi;

%macro fetchstate(Statelist= ,

 

Currdate= );

%Let cnt=1;

%Let Thisstate=%scan(&StateList, &cnt, %Str( ) );

%Do %While (&Thisstate NE );

 

proc import out= &Thisstate

datafile="&DorsHHFPath/&Thisstate./&Thisstate._HHF_STM_ToState_&CURRDATE_KEY._01.csv"

 

dbms=CSV replace ;

getnames=no;

datarow=3;

 

run;

 

/*** Advance counter and select next state ***/

%Let cnt=%eval(&cnt + 1);

%Let Thisstate=%scan(&StateList, &cnt, %Str( ) );

%End;

%Mend;

 

%fetchstate(StateList=&StateList,

Currdate=&Currdate);

 

&CURRDATE_KEY represents todays date.  This macro script creates a work file if the date extention is todays date.  If not the script generates an error.  Is there a way to avoid the error with some type of else statement that says 'no file' ??

Super User
Posts: 9,574

Re: Else statement in proc import macro

Use the fexist() function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 22,850

Re: Else statement in proc import macro

Check SAS 9.4 macro appendix for a macro that shows how this can be executed, where empty data set gets an empty record. There example is for export but I think you’ll get the idea. 

Ask a Question
Discussion stats
  • 2 replies
  • 67 views
  • 0 likes
  • 3 in conversation