If I have a data with these variables:
product year sales_jan sales_feb sales_mar....sales_nov sales_dec
How can I transpose it to something like this?
product year month sales
Month is a number (1-12).Thank you.
I would use a DATA step, and create MONTH as a numeric variable:
data want;
set have;
array monsales {12} sales_jan sales_feb sales_mar sales_apr sales_may sales_jun
sales_jul sales_aug sales_sep sales_oct sales_nov sales_dec;
do month = 1 to 12;
sales = monsales{month};
output;
end;
drop sales_: ;
run;
Or replace steps 2-4 with a set of 13 IF/THEN statements, one for each month and one to catch errors.
I would use a DATA step, and create MONTH as a numeric variable:
data want;
set have;
array monsales {12} sales_jan sales_feb sales_mar sales_apr sales_may sales_jun
sales_jul sales_aug sales_sep sales_oct sales_nov sales_dec;
do month = 1 to 12;
sales = monsales{month};
output;
end;
drop sales_: ;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.