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

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@srinath3111

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;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

ballardw
Super User

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.

Patrick
Opal | Level 21

@srinath3111

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 857 views
  • 0 likes
  • 4 in conversation