BookmarkSubscribeRSS Feed
adrfinance
Obsidian | Level 7

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?

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @adrfinance 

 

You can try the YYQ format:

data have;
	input date:YYMMDD10.;
	format date YYQ.;
	datalines;
2017-06-30
;
run;

 

ed_sas_member
Meteorite | Level 14

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;
adrfinance
Obsidian | Level 7

Can you please take the values from a variable instead of using inline?

Kurt_Bremser
Super User

@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.

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 1903 views
  • 0 likes
  • 3 in conversation