BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Hi Sas Experts,

 

Is there is anyway to create a  single macrovariable for different columns.  My intension is I want to create a macrovariable for all the products.

I mean the macro variable should populate all the products for each id. Please help.

Below is my code;


data sample;
infile datalines missover;
input id sales product1$ product2$ product3$ product4$;
datalines;
101 10 sofa
102 20 bed chair
103 30 mouse
104 49 desk phone bottle watch
run;

6 REPLIES 6
Reeza
Super User

What do you want as an output and why do you think you need a macro variable. 

sanjay1
Obsidian | Level 7

Hi Reeza,

 

I have a large data set and I want to claculate the sales for each ID and theire corresponding products.

again am sending this report to different people using sas. 

 

Thanks

 

Reeza
Super User

@sanjay1 wrote:

Hi Reeza,

 

I have a large data set and I want to claculate the sales for each ID and theire corresponding products.

again am sending this report to different people using sas. 

 

Thanks

 


That doesn't explain what you want as output or why you need a macro variable. Or even what values you want in a macro value. 

 

I could guess and say most likely all you need is a transpose so you can sum your report in various methods. But that's a guess. 

sanjay1
Obsidian | Level 7

Thanks Reeza,

 

That helps me.

 

ballardw
Super User

I think you are looking for report. Something like this:

 

proc tabulate data=have;

   class ID product;

   var sales;

   table Id, /* this produces one "page" for each ID*/

           product,  /* one row for each product*/

           Sales *(n='Number of Sales' Sum='Total of Sales')

    ;

run;

Michiel
Fluorite | Level 6

 

Add distinct column product1 into macro variables.

 

%MACRO sample;

proc sql noprint;
select distinct
product1 into :var1-:var9999
from sample
;
%LET nItems=&SQLOBS.;
%PUT nItems=&nItems.;
quit;

%DO Item=1 %TO &nItems.;

%PUT var&Item.=&&var&Item..;
%END;

%MEND;

%sample;

 

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