BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Walternate
Obsidian | Level 7

Hi all,

 

I have a long dataset that contains file "pairs." Some pairs have identical names, others have similar but not exactly the same.  I have the date, name, and ext for each file:

FNM1       FDT         FEXT          FNM2      FDT2       FEXT2

abc          1/1/19          csv            abc           1/1/20     XLS

abc          1/1/19          csv            abc_d       2/1/20    CSV

def          2/1/19          csv            def            3/1/20     XLS

ghi           3/1/19          csv            ghi            4/1/20     XLS

ghi           3/1/19          csv            ghi             5/1/20    XLSX

 

What I'm trying to do is flag weird cases for examination. A "normal" case that I would expect to see would be:

 

                 F1 is a CSV 

                  F2 is an XLS with the same name (dates don't really matter here)

 

If anything else is going on, I'd like to flag for examination, so for example:

               1) F1 and F2 are both CSVs (these would have slightly different names)

               2) F1 is CSV and F2 is XLSX (same name)

 

So basically what I'm looking to do is build an output so I can examine all cases that are not the "normal" case that I outlined above.

 

Any  help is much appreciated.

 

1 ACCEPTED SOLUTION

Accepted Solutions
A_Kh
Lapis Lazuli | Level 10

Based on provided condition, this code will flag it. 

data want;
	set have;
	length case $10;
	if strip(upcase(fnm1)) eq strip(upcase(fnm2)) then do;
		if upcase(strip(fext)) eq 'CSV' and upcase(strip(fext2)) eq 'XLS' then Case='Normal';
		else if upcase(strip(fext)) eq 'CSV' and upcase(strip(fext2)) eq 'XLSX' then Case='Not normal';
	end;
	else Case='Not normal';
proc print;run; 

View solution in original post

3 REPLIES 3
ballardw
Super User

And the output should look like what exactly?

A_Kh
Lapis Lazuli | Level 10

Based on provided condition, this code will flag it. 

data want;
	set have;
	length case $10;
	if strip(upcase(fnm1)) eq strip(upcase(fnm2)) then do;
		if upcase(strip(fext)) eq 'CSV' and upcase(strip(fext2)) eq 'XLS' then Case='Normal';
		else if upcase(strip(fext)) eq 'CSV' and upcase(strip(fext2)) eq 'XLSX' then Case='Not normal';
	end;
	else Case='Not normal';
proc print;run; 
Quentin
Super User

Sounds Like:

data want;
  set have;
  Flag = NOT (FEXT='csv' and FEXT2 ='XLS' and FNM1=FNM2) ;
run;

Flag will be 0 when a record meets the 'normal' condition, and will be 1 when a record is not normal.

 

This is like an assertion.  You write an expression you expect to be true, and flag the records where it is not true.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 887 views
  • 0 likes
  • 4 in conversation