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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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