BookmarkSubscribeRSS Feed
apjohnson2
Calcite | Level 5

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

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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'???

--
Paige Miller
apjohnson2
Calcite | Level 5

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

PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller
apjohnson2
Calcite | Level 5

Thanks!  Do you know how to check if they are missing or not missing, instead of being equal to value X?

PaigeMiller
Diamond | Level 26

Use '.' instead of 'X' in FINDC

 

Use . instead of 'X' in WHICHN

--
Paige Miller
apjohnson2
Calcite | Level 5

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;

 

 

PaigeMiller
Diamond | Level 26

Please give it a try and see what happens.

--
Paige Miller

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1078 views
  • 2 likes
  • 2 in conversation