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.
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;
And the output should look like what exactly?
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.