BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAShole
Pyrite | Level 9

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:

datelower_estmid_estupper_eststd_devsubsystemforecast

Attached is the file i'm trying to import. Any Hints?

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

5 REPLIES 5
Haikuo
Onyx | Level 15

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

SAShole
Pyrite | Level 9

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?

Haikuo
Onyx | Level 15

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

art297
Opal | Level 21

: the first line of the file and every 77th row afterword will have a value of mod(_n_,76) equal to 1.  Thus, for those records, they are read and then simply ignored.

The fields in all of the other records are read and then output.

SAShole
Pyrite | Level 9

Thanks Haikou, this is just what I was looking for Smiley Happy

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1205 views
  • 0 likes
  • 3 in conversation