BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
How to read date jan 2010 as 01-2010 from the following txt file?
S:\FSPR\TMOP\SAS\INFILES\txtfiles\Jan 2010 ZUD.txt
1 REPLY 1
deleted_user
Not applicable
Hello,

If I understand it correctly, this may help you:



[pre]
%let test=%str(S:\FSPR\TMOP\SAS\INFILES\txtfiles\Jan 2010 ZUD.txt);

data _null_;
*begin reading from interior:
1. substract the last part of the string:
scan("&test",-1,'\'
2. find out the first blank in the extracted string (notice the use of 1- length("&test") which determines the function to look form right to left):
find(scan("&test",-1,'\'),' ',1-length("&test"))
3. Use the substr function to extract Jan 2010
4. You will get a character variable which has the value Jan 2010;
x=substr(scan("&test",-1,'\'),1,find(scan("&test",-1,'\'),' ',1-length("&test")));
*transform the character variable to numeric variable so you can output it with whatever format you want;
b=input(x,monyy8.);
put b mmyyd.;
run;

[/pre]

Marius

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 630 views
  • 0 likes
  • 2 in conversation