BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jdub
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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;

jdub
Calcite | Level 5

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

art297
Opal | Level 21

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.

Linlin
Lapis Lazuli | Level 10

Hi Art,

You are a Master, not a novice.:smileylaugh:

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1112 views
  • 0 likes
  • 3 in conversation