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

Whilst I normally advise against proc import, in this case it may be the easiest.  As for the file, you can pretty easily read it in and drop those line where first line="#".

Something like this:

data _null_;

     infile "xyz.txt";

     file "xyz.txt";

     input buffer $varying256.;

     if substr(buffer,1,1)="#" then delete;

     else put buffer;

run;

Lin_Clare
Calcite | Level 5

How to set the length variable after $varying in this case? sorry I am a SAS newbie. "input buffer $varying256.;" get an error as

ERROR: Variable name containing length expected after $VARYING

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well the point being is that you are not actually creating your dataset at this point.  The example is present to remove any lines with the first character being a hash:

data _null_;

  length buffer $2000.;

     infile "s:\temp\rob\a.txt";

     file "s:\temp\rob\a.txt";

     input buffer $;

     if substr(buffer,1,1)="#" then delete;

     else put buffer;

run;

The file a.txt has 3 rows to start, one with a hash as first character, after program is run there are only two rows.  The demonstrates how to remove the header information from your file.

Lin_Clare
Calcite | Level 5

It works, but still need to add some codes to do that for all the 80 files,output file name sepcified after file stament can not be the same as the input file after infile satment, otherwise the file will not be updated.

RW9, Thanks for you explains.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 18 replies
  • 3774 views
  • 9 likes
  • 6 in conversation