Help using Base SAS procedures

Change quarterly format

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Change quarterly format

[ Edited ]

Hi, 

 

I have a beginner question.

I have two databases in quarterly data. In one of them the variable quarterly is in format $8. (ex: 1991Q1, 1991Q2, 1991Q3 etc) and in the other is in format DDMMYY10 (ex: 01/01/1996 is the first quarter, 01/04/1996 the second, etc).

I need both variables in the same format to make a Merge by the variable in quarterly.

I tried that but it did not work, i get the numbers such 13149, 13240 and i don't undestand why.

 

DATA IPCH_trim ;
set ipch_trim ;
format trim $8. ;
run ;

 

Can you help me to change the format please?. Ideally to change the variable in DDMMYY10  format to the format $8.

 

Thanks you very much

Attachment
Attachment

Accepted Solutions
Solution
‎02-21-2018 03:05 PM
Super User
Posts: 23,771

Re: Change quarterly format

Posted in reply to luciacossaro

luciacossaro wrote:

Hi, 

 

I have a beginner question.

I have two databases in quarterly data. In one of them the variable quarterly is in format $8. (ex: 1991Q1, 1991Q2, 1991Q3 etc) and in the other is in format DDMMYY10 (ex: 01/01/1996 is the first quarter, 01/04/1996 the second, etc).

I need both variables in the same format to make a Merge by the variable in quarterly.

I tried that but it did not work, i get the numbers such 13149, 13240 and i don't undestand why.

 

DATA IPCH_trim ;
set ipch_trim ;
format trim $8. ;
run ;

 

Can you help me to change the format please?. Ideally to change the variable in DDMMYY10  format to the format $8.

 

Thanks you very much


I would assume that you would convert it to the quarter but it would help if you showed what the variables look like. 

EIther way, use PUT to convert it to a character value, assuming a SAS date to start with:

 

new_value = put(date, yyq6.);

Play around with the second parameter to get what you want. Also, if you're joining via SQL you can do this on the fly. 

View solution in original post


All Replies
Solution
‎02-21-2018 03:05 PM
Super User
Posts: 23,771

Re: Change quarterly format

Posted in reply to luciacossaro

luciacossaro wrote:

Hi, 

 

I have a beginner question.

I have two databases in quarterly data. In one of them the variable quarterly is in format $8. (ex: 1991Q1, 1991Q2, 1991Q3 etc) and in the other is in format DDMMYY10 (ex: 01/01/1996 is the first quarter, 01/04/1996 the second, etc).

I need both variables in the same format to make a Merge by the variable in quarterly.

I tried that but it did not work, i get the numbers such 13149, 13240 and i don't undestand why.

 

DATA IPCH_trim ;
set ipch_trim ;
format trim $8. ;
run ;

 

Can you help me to change the format please?. Ideally to change the variable in DDMMYY10  format to the format $8.

 

Thanks you very much


I would assume that you would convert it to the quarter but it would help if you showed what the variables look like. 

EIther way, use PUT to convert it to a character value, assuming a SAS date to start with:

 

new_value = put(date, yyq6.);

Play around with the second parameter to get what you want. Also, if you're joining via SQL you can do this on the fly. 

☑ This topic is solved.

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

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