BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abdulla
Pyrite | Level 9
Dateprice
198907311.981
199007311.287
199107311.792
199212317.271
1993123113.017
1994123122.317
1998123127.857
1999123126.242
2000123135.12
2001123112.808
2002123111.907
199012315.656
199112313.85

 

From the above data I want to keep data related 31st December. So, I need code for YR1231. Please help

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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;

View solution in original post

12 REPLIES 12
ed_sas_member
Meteorite | Level 14

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.

abdulla
Pyrite | Level 9
Hi, how will I do that without input command?
ed_sas_member
Meteorite | Level 14

Hi, is your file already a SAS dataset?

ed_sas_member
Meteorite | Level 14

Perfect. And what is the type of the Date variable? (Num or Char). Is it already recognize as a date ?

abdulla
Pyrite | Level 9
I think it is num. It is exactly what I have given in the example. So, I have a large data set. I imported the excel in which date is given in the same style as my example
ed_sas_member
Meteorite | Level 14

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.

 

 

abdulla
Pyrite | Level 9
Alphabetic List of Variables and Attributes
# Variable Type Len Label
4 Assets Num 8 Assets
2 Date Num 8 Date
5 Earnings Num 8 Earnings
3 FY Num 8 FY
1 gvkey Num 8 gvkey

This is what I have
ed_sas_member
Meteorite | Level 14

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;
abdulla
Pyrite | Level 9
Thank you very much. It worked
ed_sas_member
Meteorite | Level 14

Awesome! Have a great day.

abdulla
Pyrite | Level 9
So, I have attached example of my data. Please download it and use proc import to import the data. Then what code should I use to get my desired result?

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 2030 views
  • 2 likes
  • 2 in conversation