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

Hi Sas Community!

I tried to use the "YYQ5." informat to read year-quarter date, but cant get this quite right. Can any one catch what's going wrong with the following code?

Thank you!!! Have a nice weekend.

 

data temp;

input date YYQ5. prime 4.2;

datalines;

 

18Q01 3.45

18Q02 3.44

18Q03 3.23

18Q04 1.23

19Q01 2.12

19Q02 3.23

19Q03 1.42

;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What makes you think there is a problem. You did not assign any format to DATE so the value displayed is the number of days since 1JAn1960.

The informat will assign a date value of the first day of the calendar quarter if you use a date format that will display day and month such as:

data temp;
input date YYQ5. prime 4.2;
format date date9.;
datalines;
18Q01 3.45
18Q02 3.44
18Q03 3.23
18Q04 1.23
19Q01 2.12
19Q02 3.23
19Q03 1.42
;
run;

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

View solution in original post

4 REPLIES 4
ballardw
Super User

What makes you think there is a problem. You did not assign any format to DATE so the value displayed is the number of days since 1JAn1960.

The informat will assign a date value of the first day of the calendar quarter if you use a date format that will display day and month such as:

data temp;
input date YYQ5. prime 4.2;
format date date9.;
datalines;
18Q01 3.45
18Q02 3.44
18Q03 3.23
18Q04 1.23
19Q01 2.12
19Q02 3.23
19Q03 1.42
;
run;

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

changxuosu
Quartz | Level 8
thank you so much, now I understand the difference btw formats and informats.... You're always very helpful.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data temp;

input date yyq5. prime 4.2;
datalines;
18Q01 3.45
18Q02 3.44
18Q03 3.23
18Q04 1.23
19Q01 2.12
19Q02 3.23
19Q03 1.42
;
data got;
	set temp;
	new = date;
	format new yyq5.;
run;
changxuosu
Quartz | Level 8
thank you so much, it's really helpful.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1171 views
  • 2 likes
  • 3 in conversation