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

Hi all,

 

I am using a macro to generate a non-fixed number of data-sets. I will have times when there are very few data-sets, and times when there are more (>100). 

I want to transpose all these data-sets, and am therefore using a macro (%macro transp).

 

In the call-statement for the data-set-generating-macro the format is "z1.", which only works for up to 9 data-sets. And if I have only 9 data-sets, the %macro transpose works.

If I have 10 or more data-sets, and change the format in the call-statement to z2. or z3., then the %macro transpose does not work. This is because the count-step in the beginning used 1,2,3 etc. and not 01, 02, 03 etc. which is generated by using z2.

 

Is there a format I should use instead, that will use 1,2,3,4... and up to several hundreds, without the 0's in front?

If not, is there a way to adjust the count-part of the macro, to count with 0's infront?

Or, any other suggestions on how to make it work when I have 10 or more data-sets?

 

data _null_;
	set list;
	string = catt('%import_file(', dir, ', ',  name,', ', catt('AAA', put(_n_, z1.)), ');');
	call execute (string);
	run;

%macro transp;

proc sql noprint; select count(memname) into :num from dictionary.tables where libname='WORK' and memtype='DATA' and memname eqt "AAA"; quit; %DO no=1 %TO &num.; proc transpose data=AAA&no. out=BBB&no. (drop=_name_ _label_); id A; var B; run; %END; %mend; %transp
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If you can have more than 100 data sets, why not just use Z3. always?

 

Then inside the macro

 

%DO no=1 %TO &num.;
    %let zno = %sysfunc(putn(&no,z3.));
    proc transpose data=AAA&zno. out=BBB&zno. (drop=_name_ _label_);

 

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If you can have more than 100 data sets, why not just use Z3. always?

 

Then inside the macro

 

%DO no=1 %TO &num.;
    %let zno = %sysfunc(putn(&no,z3.));
    proc transpose data=AAA&zno. out=BBB&zno. (drop=_name_ _label_);

 

 

--
Paige Miller
GustavSandberg
Calcite | Level 5

Many thanks! worked like a charm!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 908 views
  • 0 likes
  • 2 in conversation