Hi,
data ds;
infile datalines;
input a$ b$ c$ d$ e$;
datalines;
1 2 as> sd< 78#
3 5 a>a sd< 78&
1 2 <ss sd< 78*
1 2 ss 3 84
;
run;
output may be like
_n_
1
2
3
or
1 2 as> sd< 78#
3 5 a>a sd< 78&
1 2 <ss sd< 78*
I was trying
data ds1;
array spc(93) _All_;
set work.ds nobs=nobs point=i;
do i=1 to dim(spc);
where spc(i) like (<%,>%,%>%,>%,%>,%>%);
end;
stop;
run;
Thanks in advance
You need to provide a bit more explanation in your posts. Don't forget that you're asking us to help you so please have the courtesy and spend the time required to help us to help you.
Following the coding approach you've tried below code should do the job.
data have;
infile datalines;
input a$ b$ c$ d$ e$;
datalines;
1 2 as> sd< 78#
3 5 a>a sd< 78&
1 2 <ss sd< 78*
1 2 ss 3 84
;
run;
data want(drop=_:);
set work.have;
array spc(*) _character_;
do _i=1 to dim(spc);
if notalnum(compress(spc[_i])) then
do;
row=_n_;
output;
leave;
end;
end;
run;
Some information would be helpful. Special characters normally refer to tabs, or carriage return etc. I don't see any of these here?
Do you just want to see if the string contains <, >, or %? If so:
data ds1; array spc{93} _all_; set work.ds; do i=1 to dim(spc); if lengthn(compress(spc{i},'<>%',"k")) then k=1; end; if k; run;
This goes over each variable, if the string when all but <>% are removed's length is greater than 0 then k is set to 1. After all array elements are checked, if k is 1 then it gets output.
Hi,
It doesnt work.
Thanks
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
You need to provide a bit more explanation in your posts. Don't forget that you're asking us to help you so please have the courtesy and spend the time required to help us to help you.
Following the coding approach you've tried below code should do the job.
data have;
infile datalines;
input a$ b$ c$ d$ e$;
datalines;
1 2 as> sd< 78#
3 5 a>a sd< 78&
1 2 <ss sd< 78*
1 2 ss 3 84
;
run;
data want(drop=_:);
set work.have;
array spc(*) _character_;
do _i=1 to dim(spc);
if notalnum(compress(spc[_i])) then
do;
row=_n_;
output;
leave;
end;
end;
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.