BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

I have 41 variables I need to calculate a growth rate for. I have them defined in a macro loop but I don't think it can be done in a datastep.  I have:

 

data TAFOASAS.TAM_TWRS_FREQ_ALL_G;
	set EGTASK.TAM_TWRS_FREQ_ALL;
	CYYZ_FREQ_G = CYYZ_FREQ / lag12(CYYZ_FREQ) -1;
	format CYYZ_FREQ_G PERCENT10.2;
	drop cyyz_freq;
run;

 

The only thing that changes is the airport code (CYYZ in this case). Can a list be passed to create the growth rate in a loop for each airport?

 

thx.

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Can you provide an example of data containing 2 growth variables and 2 airports?

Reeza
Super User

You can do it a data step or sql merge with a variable that aligns with the time. A data step merge is better because you can then use arrays.

 

Data want;

merge have have(firstobs=12 rename = ....rename variables);

by airport etc;

 

Array declarations and processes go here. 

run; 

 

This will align the first and 12 observation. 

 

If your airport codes go across, the simplest solution is to transpose it to a long format and then use BY group processing. 

Astounding
PROC Star

If you had stored your data differently, this whole thing could be done simply.  Very simply.  One DATA step, no macro language.  However, you would need to use a better structure for the data.  Instead of adding a prefix for each airport name, store each airport's data on separate observations.  For example, instead of storing a variable named CYYZ_FREQ, store a variable named FREQ.  Also store a variable named AIRPORT.  So when AIRPORT is CYYZ, the variable FREQ holds a value related to the frequency for CYYZ airport.

 

Do you have the data available in that form?

 

The current structure to the data is just a bad idea.  It turns an easy problem into a difficult one, not just for this application but for most every application that uses this data.  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 797 views
  • 0 likes
  • 4 in conversation