I'm trying to import a text file that is stacked by a group. the first line of the file and every 77th row afterword is simply i header i wish to do away with.
There are seven fields in the file:
date | lower_est | mid_est | upper_est | std_dev | subsystem | forecast |
Attached is the file i'm trying to import. Any Hints?
Thank you !
Here is one way:
data have (drop=dt);
infile "h:\temp\data.txt";
if mod(_n_,76) =1 then input;
else do;
input dt $ 1-8
lower_est 18-34
mid_est 43-59
upper_est 67-84
std_dev 101-117
subsystem $ 120-125
forecast 147-148;
date=input(compress(dt,' /'),yymmn6.);
output;
end;
format date mmddyy10.;
;
run;
Haikuo
Here is one way:
data have (drop=dt);
infile "h:\temp\data.txt";
if mod(_n_,76) =1 then input;
else do;
input dt $ 1-8
lower_est 18-34
mid_est 43-59
upper_est 67-84
std_dev 101-117
subsystem $ 120-125
forecast 147-148;
date=input(compress(dt,' /'),yymmn6.);
output;
end;
format date mmddyy10.;
;
run;
Haikuo
Haikou can you help me to understand how your code works?
if mod(_n_,76) =1 then input;
else do;
input dt $ 1-8
lower_est 18-34
mid_est 43-59
upper_est 67-84
std_dev 101-117
subsystem $ 120-125
forecast 147-148;
date=input(compress(dt,' /'),yymmn6.);
output;
is this like saying if the record is a multiple of 76 then do nothing else read in the record and output the record to the dataset. Also how is it that the first record is skipped over? because mod(1,76) = 1 is true, correct?
Two key points:
1. SAS process data in a sequential way, one by one, unless being told otherwise. By this sense, it is harder for you to skip reading a record, this is why there is " if mod(_n_,76) =1 then input;"
2. But you can control whether to output it or not by explicitly spelling out "output" to those you want to keep. An explicit "output" statement will override the implicit one.
HTH,
Haikuo
Thanks Haikou, this is just what I was looking for
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.
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.