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-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
  • 1 reply
  • 1011 views
  • 0 likes
  • 2 in conversation