DATA Step, Macro, Functions and more

combine data vertically with easy macro variable

Not applicable
Posts: 0

combine data vertically with easy macro variable

When Im trying to submit the following code to combine the monthly data, SAS returns only the infos from the first month with log 'NOTE: LOST CARD.
i=2 lastobs=1 Flight=IA11101 Origin=HND Dest=SFO Date=14883 RevCargo=182886 _ERROR_=1 _N_=1'. What the hell is wrong with that?

data temp1 (drop=i);
%let n=9;
do i=1 to 3;
do until (lastobs);
infile "C:\Documents and Settings\Administrator\Desktop\SASPROG3data\prog3_v8\month&n..dat" end=lastobs;
input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.2;
%let n=%eval(&n+1);
Super Contributor
Super Contributor
Posts: 3,176

Re: combine data vertically with easy macro variable

Posted in reply to deleted_user
Firstly, you appear to be mixing SAS macro language constucts (the %LET macro variable assignments) with DATA step logic -- the SAS %LET statement will be resolved at SAS compile time, not with each iterative DATA step pass. Or possibly you are not sharing all SAS code, maybe, such as the surrounding %MACRO and %MEND statements necessary with a %DO %END looping technique.

Recommending reading up on the SAS MACRO facility documentation if you intend to execute your DATA step "n" times, once for each INFILE specification. Also, I noticed you may be intending to read several input files in a single DATA step execution -- which is quite possible, however you will either need to reset your lastobs variable to zero with each DO UNTIL(lastobs); END; execution -- SAS will not reset the variable for you -- another suitable technique is to change your END= SAS variable to make it unique for each %DO %END macro execution.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation