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 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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