BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
superbug
Quartz | Level 8

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;
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Set  - options obs = MAX; - before your DATA step WANT.

View solution in original post

8 REPLIES 8
superbug
Quartz | Level 8

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;

 

SASKiwi
PROC Star

Set  - options obs = MAX; - before your DATA step WANT.

Reeza
Super User
In addition to option obs=max change, I suspect you need to use the PRETEST macro variable not the TEST macro variable. You're reading the same data set and processing it multiple times, but you only have one data set in the end, whatever your TEST variable is.

superbug
Quartz | Level 8

@SASKiwi @Reeza 

Thanks you both so much!

Very much appreciate your help!

 

 

ballardw
Super User

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.

superbug
Quartz | Level 8

@ballardw 

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!

ballardw
Super User

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.

superbug
Quartz | Level 8

@ballardw 

Thank you for teaching me this!

The help I get from this forum are always very much appreciated!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 743 views
  • 1 like
  • 4 in conversation