Date | price |
19890731 | 1.981 |
19900731 | 1.287 |
19910731 | 1.792 |
19921231 | 7.271 |
19931231 | 13.017 |
19941231 | 22.317 |
19981231 | 27.857 |
19991231 | 26.242 |
20001231 | 35.12 |
20011231 | 12.808 |
20021231 | 11.907 |
19901231 | 5.656 |
19911231 | 3.85 |
From the above data I want to keep data related 31st December. So, I need code for YR1231. Please help
Could you please try this ?
data have2;
set have;
format date2 date9.;
date2 = input(put(date,8.),yymmdd8.); /* Date2 = date in a date format*/
run;
HI @abdulla ,
Maybe this is something you can try:
data have;
input Date yymmdd8. price;
format Date date9.;
cards;
19890731 1.981
19900731 1.287
19910731 1.792
19921231 7.271
19931231 13.017
19941231 22.317
19981231 27.857
19991231 26.242
20001231 35.12
20011231 12.808
20021231 11.907
19901231 5.656
19911231 3.85
;
run;
data want;
set have;
where month(date)=12 and day(date)=31;
run;
Hope this help.
Hi, is your file already a SAS dataset?
Perfect. And what is the type of the Date variable? (Num or Char). Is it already recognize as a date ?
OK. I encourage you to check the variable type / format / etc. by using a proc contents:
proc contents data=have;
run;
If it is a character variable, you will a have to convert it using the input() function or the substr() function depending if you need to have this variable as a date.
If it is a numeric variable, you will a have to apply a date format.
Could you please try this ?
data have2;
set have;
format date2 date9.;
date2 = input(put(date,8.),yymmdd8.); /* Date2 = date in a date format*/
run;
Awesome! Have a great day.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.