Hi everyone!!
In order to find errors what i want to do is to read only the files on the text plain (.txt) that have a lenght of less than 46.
I thought about first load all the lines with his input of the variables, and then create one conditional with sums of lenght of all variables but i guess there is a easy and shorter way.
Thanks for the help!!
ps; sorry for my english
Sorry, not a clue what you are on about. You mean you have a text file, and you want to read it line by lin and if the line is less than 46 characters you want to increment a counter? If so:
data want; infile "abc.txt"; input; retain total; if lengthn(_input_) < 46 then total=sum(total,1); run;
To help in defining your issue:
- you have a bunch of text files, named *.txt, in a certain location (directory)
- you want to find files that have a record (line) length of less than 46
- do you want to flag a file if one line is less than 46, or all lines?
- as a corollary, do those files all have fixed-length records (lines), or is line length variable within each file?
Sorry RW9 and KurtBremser for my explication.
I have one plain text with the atributes delimited by a registre like this:
@1 &cursoacademico 4.
@5 &tipodocumento 1.
@6 &documento $ 9.
@15 &sexo 1.
@16 &grupoedad 2.
@18 &curso 3.
@21 ¢ro 8.
@29 &situacionsocial 1.
@30 &situacionlaboral 1.
@31 &entrada $ 8.
@39 &salida $ 8.;
what i want to do is to avoid the reading of observations having a greater lenght that the required in the desing of the record because they are considered mistakes
So this is your file description:
@1 &cursoacademico 4.
@5 &tipodocumento 1.
@6 &documento $ 9.
@15 &sexo 1.
@16 &grupoedad 2.
@18 &curso 3.
@21 ¢ro 8.
@29 &situacionsocial 1.
@30 &situacionlaboral 1.
@31 &entrada $ 8.
@39 &salida $ 8.;
Why the & before the text such as &salida? That is macro code.
Anyways, back to your problem. Where do you arrive at the above specification - i.e. each of these variables should be that given length? If you have that written down, and the file does not conform to that spec then the file should be rejected outright and returned to the sender to get fixed. You can try to fix it yourself, but then what would happen if it changes next time, or someone else tries to reproduce what you have done or take over your work. Remember, specification is far more important than coding or anything else, it is the key basis for any work and if that is not correct and acurate nothing else will be.
Before making code flexible, make it run correctly.
Therefore eliminate all macro references; there is absolutely no sense engaging in macro programming when you haven't mastered basic SAS data step code yet.
If you want to flag single records on length, use this construct:
data want;
infile "name_of_file" length=lvar;
input
/* your variable list here */
;
if lvar > 46
then errorflag = 'Y';
else errorflag = 'N';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.