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
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_);
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_);
Many thanks! worked like a charm!
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.