there are 4 datasets a,b,c,d.
How to look for a vraible name that has TEST in variablename like ATEST, BTEST and see if there aleast one record misssing?
Table A:
Id ATEST
1 Testa
2 Testa
Table B:
Id BTEST
1 Testb
2
Table C:
Id CTEST
1 TestC
2 TestC
Table 😧
Id DTEST
1
2
So the output would be:
Dataset B BTEST
Dataset D DTEST
@SASPhile,
This may give you an idea on how to proceed
%macro VarExist(ds, var);
%local rc dsid result;
%let dsid = %sysfunc(open(&ds));
%if %sysfunc(varnum(&dsid, &var)) > 0 %then %do;
%let result = 1;
%put NOTE: Var &var exists in &ds;
%end;
%else %do;
%let result = 0;
%put NOTE: Var &var not exists in &ds;
%end;
%let rc = %sysfunc(close(&dsid));
&result
%mend VarExist;
/* Usage */
%put %VarExist(sashelp.class, name);
%put %VarExist(sashelp.class, aaa);
Source : http://www.sascommunity.org/wiki/Tips:Check_if_a_variable_exists_in_a_dataset
I'm not looking if a variable exists. I'm looking for a variable that contains TEST as part of variablename and if it has at least one missing values.
@SASPhile wrote:
I'm not looking if a variable exists. I'm looking for a variable that contains TEST as part of variablename and if it has at least one missing values.
HOW many variables are you concerned with in each data set? What does the output potentially look like with 10 variables?
And are you really sure that you want every variable that may have 'TEST' as part of the name? What if you have a variable named "testimony" "intestate"
Do you want each time a variable is missing or if any records in the set are missing values at least once?
Are you designing this system? Can you change the naming convention so it's TESTA, TESTB, etc?
SAS works better with prefixes rather than suffixes.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.