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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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