DATA Step, Macro, Functions and more

read date from txt file

Reply
Super Contributor
Posts: 673

read date from txt file

How to read date jan 2010 as 01-2010 from the following txt file?
S:\FSPR\TMOP\SAS\INFILES\txtfiles\Jan 2010 ZUD.txt
N/A
Posts: 0

Re: read date from txt file

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

Ask a Question
Discussion stats
  • 1 reply
  • 119 views
  • 0 likes
  • 2 in conversation