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

      Proc sql;
create table				Autoreg_L6M_&t1  as 
select distinct						objectregnbr 

							,case when input(put(period,yymmn6.),best32.) GE &t6  then mean(depreciation) end as Mean_depreciation_L6m
					 


from						pricedata31
where						input(put(period,yymmn6.),best32.) GE &t6
and							input(put(period,yymmn6.),best32.) Le &t1 
group by					objectregnbr
;
Quit;

      Proc sql;
create table				Autoreg_L6M_&t2  as 
select distinct						objectregnbr 

							,case when input(put(period,yymmn6.),best32.) GE &t7  then mean(depreciation) end as Mean_depreciation_L6m
					 


from						pricedata31
where						input(put(period,yymmn6.),best32.) GE &t7
and							input(put(period,yymmn6.),best32.) LE &t2 
group by					objectregnbr
;
Quit;
 

As you see this can get super repetitive with 36 months to go.

 

Are there any way to make this loop over and increase to the next macro variable?

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The simple answer is don't model your data that way.  You are trying to use SAS like Excel with a transposed thinking.  Work with long (normalised data) and then transpose up only when needed, it will make your code faster and simpler.  If you produce some test data and show what you want out, I can show you.  The alternative is you either use array processing in a datastep (second on the list of recommendations), or thirdly write some macro loops - bad idea, dodgy coding, slow etc. not recommended.

 

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The simple answer is don't model your data that way.  You are trying to use SAS like Excel with a transposed thinking.  Work with long (normalised data) and then transpose up only when needed, it will make your code faster and simpler.  If you produce some test data and show what you want out, I can show you.  The alternative is you either use array processing in a datastep (second on the list of recommendations), or thirdly write some macro loops - bad idea, dodgy coding, slow etc. not recommended.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 655 views
  • 0 likes
  • 2 in conversation