I used the following syntax to read in a bunch of .csv file. Each file being read in contains 250 rows. I then stacked them together, get a "want" dataset.
%macro yy (pretest);
options obs=253;
proc import datafile=".....\&test..csv"
dbms=csv replace out=&test;
guessingrows=max;
datarow=4;
run;
%Mend;
%PT(PAA08600);
%PT(PAA08601);
%PT(PAA08602);
%PT(PAA08603);
%PT(PAA08604);
/* stack all files*/
data want;
set PAA08600
PAA08601
PAA08602
PAA08603
PAA08604
I checked the stacked file, i.e. want data, the records/lines are the correct number, which is 1250 rows, but when I export "want" using the following code, it turned out the resulted data in the designated folder only contains records for one file/test, i.e., 250 rows. I can't figure out why. Please help. Thanks!
proc export data=want
outfile="....\want.csv"
dbms=csv replace; run;
Set - options obs = MAX; - before your DATA step WANT.
sorry, there is a typo in the code I posted. the correct code should be following
%macro PT(pretest);
options obs=253;
proc import datafile=".....\&test..csv"
dbms=csv replace out=&test;
guessingrows=max;
datarow=4;
run;
%Mend;
%PT(PAA08600);
%PT(PAA08601);
%PT(PAA08602);
%PT(PAA08603);
%PT(PAA08604);
/* stack all files*/
data want;
set PAA08600
PAA08601
PAA08602
PAA08603
PAA08604
the export data "want"
proc export data=want
outfile="....\want.csv"
dbms=csv replace; run;
Set - options obs = MAX; - before your DATA step WANT.
You "typo" fix actually still means nothing from what you show. The name of the macro parameter is Pretest and you do not use &pretest anywhere. So the question might be what does &test represent and where was it set.
You also don't show ending the data Want step at all.
And why did you bother to set Options obs=253????.
But you do need to set it back as the option stays in effect until reset.
In general inside any macro that sets SYSTEM options you should make sure to set them back before the end of the macro.
Thank you for catching those typo.
I edited the code before posting, which resulted typo error.
It should be pretest inside the macro.
For data stacking portion, I forgot to end the code with semicolon and "run".
I will be very careful next time checking the code before I post.
Thanks again!
There are reasons that we suggest posting the LOG so often. It is very easy to retype something and introduce errors. Copy the data step, procedure or combinations that seem not work from the LOG and paste them into a text box opened on the forum with the </> icon.
When debugging macro code you often want to use the system option MPRINT.
options mprint;
%mymacrocall
options nomprint; /* turn if off*/
The Mprint option will show details of the code generated.
And a very good habit to get into is always end a data step or procedure called in a macro with the Run; statement.
Thank you for teaching me this!
The help I get from this forum are always very much appreciated!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.