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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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