- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data ds ;
infile datalines ;
input name$ 15;
cards;
abc_11234567898
abc_112345678989
;
run;
in above data I have 15 characters length observation only only , above 15 character length I don't. please anyone help me how to remove above 15 char length variable.
- Tags:
- sas
- SAS programming
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The LENGTH function will measure the length of variables.
The DELETE statement will delete observations.
In combination:
data ds ;
infile datalines ;
length name $ 16;
input name;
if length(name) ne 15 then delete;
cards;
abc_11234567898
abc_112345678989
;
DO NOT set the length of NAME to 15, or else you can't detect those rows that originally were longer than 15.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A few points ...
Evidently you made an error posting the question. The INPUT statement is missing a dot:
input name$ 15.;
not
input name$ 15;
If you want more than 15 characters, you need to define a variable that is more than 15 characters long. One way:
data ds ;
infile datalines ;
length name $ 16;
input name;
cards;
abc_11234567898
abc_112345678989
;
In the LENGTH statement, choose whatever length you would like for your variable. It doesn't have to be 16.
Notice that once the variable's length is already defined by the LENGTH statement, you can simplify the INPUT statement.
Also notice that you don't need a RUN; statement. Since the CARDS section can only appear at the end of a DATA step, the presence of a CARDS statement triggers SAS to run the DATA step (whether or not you have a RUN statement).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
char or below 15 char should be deleted please help me on that .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The LENGTH function will measure the length of variables.
The DELETE statement will delete observations.
In combination:
data ds ;
infile datalines ;
length name $ 16;
input name;
if length(name) ne 15 then delete;
cards;
abc_11234567898
abc_112345678989
;
DO NOT set the length of NAME to 15, or else you can't detect those rows that originally were longer than 15.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the goal is to check how long the string was on the line that is being read then testing the length of what ended up in the variable is the wrong test.
Instead you could test how many characters before the last non-blank character there were in the line by testing the _INFILE_ automatic variable.
input string $15.;
if length(_infile_) > 15 then delete;