Hello,
I have a dataset that has date entried in the following form:
2017-06-30
2017-06-30
and I would like to generate a new variable that has the year and the quarter in the following format:
YYYYQQ
i.e. the above entries would be:
2017Q2
How can I do that?
Hi @adrfinance
You can try the YYQ format:
data have;
input date:YYMMDD10.;
format date YYQ.;
datalines;
2017-06-30
;
run;
If the initial variable is a character variable and not a SAS date, you can use the input() function:
data have;
input date $10.;
format date_q YYQ.;
date_q = input(date, YYMMDD10.);
datalines;
2017-06-30
;
run;
Can you please take the values from a variable instead of using inline?
@adrfinance wrote:
Can you please take the values from a variable instead of using inline?
Datalines and input CREATE A VARIABLE, so your question is nonsense.
If you want to read existing values from a dataset, use the set statement, and the variables from the incoming dataset.
PS if you want code that is applicable to your data, it is necessary to supply that data, in a data step with datalines (see the gazillion examples her on the communities).
Use the "little running man" to post your code.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.