BookmarkSubscribeRSS Feed
chanduk
Obsidian | Level 7

I have a below datset contains the variables Case_opened_month,Average_days.How will I get the below desired output

Dataset : A
=============

Case_opened_month       Average_days

APR17                                  10
AUG16                                  20
DEC16                                  30
FEB17                                 4.6
JAN17                                 30
JUL16                                  0
JUN17                                 0
MAR17                               0
MAY17                               40
NOV16                               25
OCT16                              15
SEP16                              35

 

 

Desired Output dataset A
-------------------------------

Case_opened_month       Average_days

JUL16                                  0
AUG16                                20
SEP16                                 35
OCT16                               15
NOV16                              25
DEC16                             30
JAN17                             30
FEB17                           4.6
MAR17                           0
APR17                          10
MAY17                          40
JUN17                           0

 

 

 

Regards,

chandu

1 REPLY 1
ballardw
Super User

Almost anything involving dates works much better if you create a SAS date valued variable. Then sorting is actually by date order plus there are many functions and formats to manipulate the data.

 

The following code creates a SAS date valued variable you could use to sort the data.

data have;
   set want;
   SASdate = input(case_opened_month,MONYY5.);
   format SASdate  MONYY5.;
run;

proc sort data = want;
   by SASdate;
run;

Note the SASDATE variable created this way will assume a day of the month of 1 for all of the values.

 

If you use a different FORMAT for SASDATE you can change appearance such as display 04/01/2017, 01APR17 or 01APR2017 or even calendar quarters without adding new variables. The formats can also be used to group values for analysis or summary.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 922 views
  • 0 likes
  • 2 in conversation