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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 833 views
  • 0 likes
  • 2 in conversation