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!

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
  • 2 replies
  • 285 views
  • 0 likes
  • 2 in conversation