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;

 

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