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

Dear All,

 

I'm trying to append the 100 files from test001-test100;

when i run the below code 


%macro append_all;
%do i=001 %to 194;
proc append base=final_mar data=test&i force; run;
%end;
%mend append_all;
%append_all;

 

the appending starts only from test100 file to test194... below 100 files are not appending what may be the reason?

 


Regards,

Anil

1 ACCEPTED SOLUTION

Accepted Solutions
error_prone
Barite | Level 11

The leading zeros are automatically removed, because numbers don't have leading zeros.

 

Best way to solve the issue is following @RW9 posts. If you can't fix the problem, try this:

 

%macro appending;
   %local dsn;
   
   %do dsn = 001 %to 194;
      %let dsn = %sysfunc(putn(&dsn, z3.));
      proc append base=work.complete new=work.a&dsn;
      run;
   %end;
%mend;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This question is asked a lot, and the root cause of it is mismanaged programming before this step.  How did you get 100 of datasets?  Whats the betting that you have done some sort of loop over some data and for each by group you have created a new dataset for output.  Your now stuck with a ton of datasets to append back together.  The simplest method is not to fight the programming language, use by grouping for ultimate performance and simpler coding.  For instance, if you were doing means like this:

...
  %do i=1 %to 100;
    proc means data=...
where bvar=&i.; output out=want&i.; run; %end; ...

You would end up with 100 datasets all much the same, and then need to work with those.  You could use by grouping to vastly simplfy:

proc means data=...
  by bvar;
  output out=want;
run;

This produces one dataset, with all the first codes output information, grouped by the bvar variable.  You can then further process this without need to append lots of data.

error_prone
Barite | Level 11

The leading zeros are automatically removed, because numbers don't have leading zeros.

 

Best way to solve the issue is following @RW9 posts. If you can't fix the problem, try this:

 

%macro appending;
   %local dsn;
   
   %do dsn = 001 %to 194;
      %let dsn = %sysfunc(putn(&dsn, z3.));
      proc append base=work.complete new=work.a&dsn;
      run;
   %end;
%mend;
ballardw
Super User

Here is an example of what @error_prone means about the values of your index variable:

%macro dummy;
%do i=001 %to 194;
   %put macro variable i resolves to: &i;
%end;
%mend;
%dummy;

The log will show what &i is as seen when resolved in loop.

 

Reeza
Super User
data want;
set test001-test194;
run;

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
  • 4 replies
  • 5233 views
  • 4 likes
  • 5 in conversation