BookmarkSubscribeRSS Feed
SASAna
Quartz | Level 8

Need help with the below question. scan(files,1,' ') ^= 'No' is not working. & all are going to filename1. 

 

some files have 'No records found' & wanted this to go to filename2.

 

%Macro test(SUMMAR= );

 

PROC SQL ;
select files into :filename1 separated by '~'
from &SUMMAR where scan(files,1,' ') ^= 'No' ;
%LET FILE_COUNT1=&sqlobs;
QUIT;

 

PROC SQL ;
select files into :filename2 separated by '~'
from &SUMMAR where scan(files,1,' ') = 'No' ;
%LET FILE_COUNT2=&sqlobs;
QUIT;

 

code continues...

 

%MEND;

 

Thanks,

Ana

 

 

6 REPLIES 6
Reeza
Super User

Comparisons are case sensitive and you could have a trailing space perhaps?

 

Check what the SCAN function is returing directly with a PUT statement or data step and then compare that to your criteria.

ballardw
Super User

Show some actual data.

SASAna
Quartz | Level 8

Hi,

 

Data is bunch of files and some of them will be like 'No records'.  I want to identify them by splitting them.

 

Thanks,

Ana

PGStats
Opal | Level 21

Try to see the content of that first word with:

 

PROC SQL ;
select 
	files, 
	scan(files, 1, ' ') as firstWord format=$8.,
	scan(files, 1, ' ') as firstWordHex format=$hex16.
from &SUMMAR;
quit;
PG
SASAna
Quartz | Level 8

I came up with below code , thought of sharing with you all.

 

Thanks for all your suggestions. I really appreciate it.

 

PROC SQL ;
select files into :filename1 separated by '~'
from &SUMMAR where scan(files,1,' ') like '%no%';
%LET FILE_COUNT1=&sqlobs;
QUIT;

 

 

PROC SQL ;
select files into :filename2 separated by '~'
from &SUMMAR where scan(files,1,' ') not like '%no%';
%LET FILE_COUNT2=&sqlobs;
QUIT;

 

Thanks,

Ana

 

Reeza
Super User

Your query is using a table. What does that table look like?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 9509 views
  • 0 likes
  • 4 in conversation