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
PROC Star

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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