DATA Step, Macro, Functions and more

using the same array code on many data sets with the same layout in one data step

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

using the same array code on many data sets with the same layout in one data step

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.


Accepted Solutions
Solution
‎03-21-2012 05:36 PM
PROC Star
Posts: 7,489

using the same array code on many data sets with the same layout in one data step

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


All Replies
Solution
‎03-21-2012 05:36 PM
PROC Star
Posts: 7,489

using the same array code on many data sets with the same layout in one data step

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;

Contributor
Posts: 33

using the same array code on many data sets with the same layout in one data step

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

PROC Star
Posts: 7,489

using the same array code on many data sets with the same layout in one data step

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.

Super Contributor
Posts: 1,636

using the same array code on many data sets with the same layout in one data step

Hi Art,

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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