Hello I use SAS EG and I'm wondering if there is a way to compress this kind of code, so I don't have to write 100 rows. If Columns 1 to 100 are together in the data, then if you wanted to keep those columns you could do keep Column1--Column100, is there something similar you could do here?
if Column1 = X and
Column2 = X and
...
Coloumn100 = X
then do Y
Checking for clarification ... do you want to find one (or more) of COLUMN1-COLUMN100 which has the value 'X', or do ALL columns have to have value 'X'???
I'm curious about either. Also I would like to know how to check if many columns are missing or not missing, both for character and numeric. I know this is a lot, but the case I'm most interested in at the moment is checking something like this, for numeric variables, where if at least one field is not missing, then do X
if not(
Column1 = .
and Column2 = .
...
and Column100 = .)
then do X
Find if all columns are the value 'X'
string=(cat(of column1-column100));
if findc(trim(string),'X','k')=0 then ...
Find if one (or more) of the columns have the value 'X'
if whichc('X',of column1-column100)>0 then ...
If the variables are numeric, then you would use the WHICHN function.
The columns do not have to be together, but all 100 must be exist.
Thanks! Do you know how to check if they are missing or not missing, instead of being equal to value X?
Use '.' instead of 'X' in FINDC
Use . instead of 'X' in WHICHN
Thanks! One more question, if I have a long list of columns that are not numbered, but are together in the data, is there a way to use the "--" functionality somehow? For example I would like to compress the following code, where the columns BI through Roof are together in the data:
proc sql;
select distinct Variable into: varlist separated by ' ' from factor.vehfactor_RAD7MM
where CustomerGroup in ('ABM','AFF','RV')
and Variable not in ('SymbolLiab','SymbolPhy','AgeSymDed','VehHisCodeNew','IRM'
,'NewBusDisc','SRMCode_v41','SR_Group', 'TerritoryNew'
)
and not (BI = . and
PD = . and
MED = . and
UMBI = . and
UMPD = . and
COMP = . and
COLL = . and
PERS = . and
FTBI = . and
RENT = . and
TOW = . and
CUST = . and
AAE = . and
ADD = . and
DimDed = . and
RVVL = . and
RVMX = . and
PPMX = . and
RVEE = . and
RVConsign = . and
Pest = . and
Roof = .
)
;
quit;
Please give it a try and see what happens.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.