DATA Step, Macro, Functions and more

Creating a macro variable for different columns

Reply
Frequent Contributor
Posts: 117

Creating a macro variable for different columns

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;

Super User
Posts: 19,820

Re: Creating a macro variable for different columns

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

Frequent Contributor
Posts: 117

Re: Creating a macro variable for different columns

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

 

Super User
Posts: 19,820

Re: Creating a macro variable for different columns


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. 

Frequent Contributor
Posts: 117

Re: Creating a macro variable for different columns

Thanks Reeza,

 

That helps me.

 

Super User
Posts: 11,343

Re: Creating a macro variable for different columns

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;

Occasional Contributor
Posts: 6

Re: Creating a macro variable for different columns

 

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;

 

Ask a Question
Discussion stats
  • 6 replies
  • 343 views
  • 0 likes
  • 4 in conversation