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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1089 views
  • 0 likes
  • 4 in conversation