Hello
I am trying to figure out how to use the same array code on many data sets with the same layout. I have quarterly data that contains three months of sales in each quarter. The data is in wide form and I am using an array to push it to long form. My goal is to reshape and append the data sets. The array code I wrote to reshape one quarter is:
data q12003;
set raw.q12003;
array q12003(3) m1 m2 m3;
do month = 1 to 3;
sales=q12003(month);
output;
end;
run;
In the raw library there are quarterly data files q12003, q22003, q32003, q42003, q12004 etc. I think it is possible to use the data step code with the array to reshape all data in raw at once without creating separate data steps for each reshape. My intuition tells me that a macro could be used for this but I am not sure how to get started.
Any help would be appreciated.
You might be able to get away with just using a wildcard. e.g.:
data all;
set raw.q:;
array q12003(3) m1 m2 m3;
do month = 1 to 3;
sales=q12003(month);
output;
end;
run;
You might be able to get away with just using a wildcard. e.g.:
data all;
set raw.q:;
array q12003(3) m1 m2 m3;
do month = 1 to 3;
sales=q12003(month);
output;
end;
run;
yah, this works.
geez, everytime I think I know a path to a solution in SAS there is always a way to fold the problem and shorten the distance to travel
FWIW: I've been trying to learn the language for the past 38 years. Every time I think I finally know everything, I discover that I'm just a novice.
Hi Art,
You are a Master, not a novice.:smileylaugh:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.