BookmarkSubscribeRSS Feed
adrfinance
Obsidian | Level 7

I have two variables

 

one is named yr and is an integer e.g. 2017

and one called quarter taking values Q1, Q2, Q3 etc.

 

How can I produce a variable called Time which contains YearQuarter concatenated e.g. 2017Q1 etc?

 

I tried this:

 

rsubmit;
DATA dataset_1;
SET dataset_1;
Time=cat(yr, quarter);
RUN;
endrsubmit; 

 

but it returns empty values

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Works fine?

 

data test;
   yr=2017;
   quarter='Q1';
   time=cat(yr, quarter);
run;
ed_sas_member
Meteorite | Level 14

Pleas provide more details as this code works fine

data dataset_1;
	input yr quarter $;
	Time=cat(yr, quarter);
	datalines;
2017 Q1
2017 Q2
2017 Q3
;
run;
adrfinance
Obsidian | Level 7

Can you post your reply with variables names insted of using datalines?

mkeintz
PROC Star

@ed_sas_member 's reply DOES have variable names.  The datalines approach is used instead of SET statements to show you that the CAT functions works - you can compare the result to the original variables YEAR and QUARTER.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------