Hi SAS,
I wish to know what is the procedure and the transformation to be used to get rid of the last record. Suppose, there is a dummy record in the last observation and I want to get rid of it using a transformation.
Ex: out of 11 recrods, the last is found to be dummy and I want to read only first 10 records..(using transformation and no user written code)Di
Moved this into for more attention by the experts.
Chris
Assuming we're talking about external data (eg. a text file) and not a table.
First question: What constitutes a dummy record? Let's assume this is a record with no data (just an empty line). So writing SAS code you could code something like:
data want;
infile blah;
input @;
if missing(_infile_) then return;
input a b c;
run;
You can "force" DI to generate such code by "injecting" it using the External File Metadata Definition under "File Parameter / Advanced"
This will generate the "infile" statement as follows:
So basically above approach allows you to "inject" any code between the generated INFILE and INPUT statement.
Does this solve your problem?
Thanks,
Patrick
Hi Patrick,
This did help and yes the file is a .txt. However, dummy means that it has data but cannot be processed further, the entire records needs to be dropped.
After I read the file successfully using the file reader, I make use of slitter to hard code the value present in the variable in row selection
I wish to know is there a workaround to strip first and last records. Just like first.variable and last.variable in datastep. The variable here is Mortgage... and if I wish to strip the first header record - I make use of _N_ ~= 1, similarly, I wish to know how to strip the last record of the file rather than hard coding to value or like operator.
Thanks,
Uaing end= infile option instead and use that for the if statement. Untested...
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.