BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ImVickie
Calcite | Level 5

Hello All,

I'm new in SAS, Plz help me with the following issue.

I'm trying to convert Date format in SAS EG

Scenario is

Month Date is given  : 201305

Output i want : May/2013

I tried below expresssion

Input(substr(YEAR_MTH,5,2) ||"/"|| substr(YEAR_MTH,1,4), mmyy7.)

Still not able to get the output

 

Thanks in advance


DateError.PNG
1 ACCEPTED SOLUTION

Accepted Solutions
BPD
Obsidian | Level 7 BPD
Obsidian | Level 7

Hi ImVickie,

 

Yo don't mention whether this is a character or numeric 201305. The code shows how to do this with character but with the numeric option commented out.

 

data a;
* daten = 201305;
* sasd = input(put(daten,6.),yymmn6.);
datec = '201305';
sasd = input(datec,yymmn6.);
newdt = put(month(sasd),monname3.)!!'/'!!PUT(Year(sasd),4.);
run;

 

Hope it's what you want.

 

Regards

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

All SAS products require that a date variable contain a full date or nothing.  You can still format the data to display month and year, but underneath the data will still be a full date:

data want;
  in_date="201305";
  processed_date=input(cats(in_date,"01"),yymmdd8.);
  format processed_date mmyy9.;
  character_date=cats(put(processed_date,monname.),'/',year(processed_date));
run;

Now you want a specific type of output not covered by the basic formats:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm

 

So you could either look into creating a picture format to create your own format, or my personal preference is create a text variable with the result. 

 

 

 

 

 

Rushikesh
Calcite | Level 5

Try this:-

 

 %let mon=201305;
 %let mon = %sysfunc( intnx( month , %sysfunc( inputn( &mon. , yymmn6. ) ) , 0 ) , date9. ) ;
 %let want=%sysfunc(catx(/,%sysfunc(substr(&mon,3,3)),%sysfunc(substr(&mon,6,4))));
 %put &want;

 

 

BPD
Obsidian | Level 7 BPD
Obsidian | Level 7

Hi ImVickie,

 

Yo don't mention whether this is a character or numeric 201305. The code shows how to do this with character but with the numeric option commented out.

 

data a;
* daten = 201305;
* sasd = input(put(daten,6.),yymmn6.);
datec = '201305';
sasd = input(datec,yymmn6.);
newdt = put(month(sasd),monname3.)!!'/'!!PUT(Year(sasd),4.);
run;

 

Hope it's what you want.

 

Regards

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
  • 3 replies
  • 840 views
  • 0 likes
  • 4 in conversation