BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I have two questions in my pgm below.  First, the data step 'one' is giving me errors when i insert in the macro.  Second, in the data step three,  depends on how many "treat" variable values i need  calculate character variables for the "value" variables. Please suggest. Thank you.

 

output needed:

 

a1     b1      c1

100   200    300

 

%macro want;
data one; input treat $ value; cards; a1 100 b1 200 c1 300 ; run; proc sql noprint; select strip(put(count (distinct treat), best.)) into: cnt from one order by treat; quit; %put &cnt.; proc transpose data=one out=two prefix=T; var value; run; %do i=1 %to &cnt.; data three; set two; n&i.=compress(put(T&i.,5.));
a1=n1;
b1=n2;
c1=n3;
run; %end; run; %mend; %want;

 

 

4 REPLIES 4
tomrvincent
Rhodochrosite | Level 12
What errors are you getting?
gamotte
Rhodochrosite | Level 12
Hello,

SAS doesn't allow to create a dataset with cards or datalines in a macro.

See "Details" section in

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#macro-stmt.htm
Kurt_Bremser
Super User

cards or datalines are not allowed in a macro. The ERROR message you get when trying to execute your macro is very clear:

ERROR: The macro WANT generated CARDS (data lines) for the DATA step, which could cause incorrect results.  The DATA step and the 
       macro will stop executing.
NOTE: The data set WORK.ONE has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

ERROR: The macro WANT will stop executing.
andreas_lds
Jade | Level 19

 

 


@knveraraju91 wrote:

Dear,

 

I have two questions in my pgm below.  First, the data step 'one' is giving me errors when i insert in the macro.  Second, in the data step three,  depends on how many "treat" variable values i need  calculate character variables for the "value" variables. Please suggest. Thank you.

 

output needed:

 

a1     b1      c1

100   200    300

 



The output of proc transpose looks very much like the required output, only thing to do is dropping the variable _name_. Why do you think that you need macro code at all?

 

EDIT: Wait, i see you need the values of "treat" as names for the transposed columns. Try:

 

   proc transpose data=one out=two(drop=_name_);
      var value;
      id treat;
   run;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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