BookmarkSubscribeRSS Feed
asar_k
Calcite | Level 5

Hello Friends,

I am trying to get my mind around this issue, and I need your advice regarding it.

I have a variable "Date" in my sas dataset in the format "01DEC05".

I want to extract the month "DEC", and the year "05" using the DATA step.

So far I tried using the SUBSTR(Right 😃 function; it does work for the char variable but it does not work for the numeric variable.

Here's my code:

data work.stocks;

set sashelp.stocks;

Inital=substr(Stock,1,1);

Month=SUBSTR(Date,3,3);

Year=SUBSTR(Date,6,2);

put @1 Month @5 Year;

run;

This being my first post here, my apologies if the code tags are not inserted properly.

Best Regards

asar_k

Ref:SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

1 REPLY 1
Ksharp
Super User

data _null_;

d='01mar2015'd;

m=put(d,monname3.);

y=put(d,year4.);

put m= y=;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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