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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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