BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

I am trying to use the below code to select where the field 'test' equals 2 and 3, based on the format.

 

proc format;
value product
2,3 = '1'
;run;

data have;
infile cards;
input test;
cards;
1
2
3
;run;

data want;
set have;
where put(test,product.) = '1';
run;

 

Am I close to something that works here, or does proc format not work like this?  My WANT and HAVE datasets are the same.  I'd like the format to filter and only keep the 2,3. 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You're still capturing the value 1. Add an other condition, e.g.:

 

proc format;
value product
2,3 = '1'
other='0'
;run;

data have;
infile cards;
input test;
cards;
0
1
2
3
4
5
;

data want;
set have;
where put(test,product.) = '1';
run;

 

HTH,

Art, CEO, AnalystFinder.com

 

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

You're still capturing the value 1. Add an other condition, e.g.:

 

proc format;
value product
2,3 = '1'
other='0'
;run;

data have;
infile cards;
input test;
cards;
0
1
2
3
4
5
;

data want;
set have;
where put(test,product.) = '1';
run;

 

HTH,

Art, CEO, AnalystFinder.com

 

Reeza
Super User

If there isn't a value in the format it keeps the value, in this case it also happens to be a 1. 

 

If you add an OTHER to your format it will resolve as expected. This is VALUE, not INVALUE. 

 

proc format ;
	value product 2, 3='1' other='0';
run;

data have;
	infile cards;
	input test;
	cards;
1
2
3
;
run;

data want;
	set have;
	where put(test, product.)='1';
	format test product.;
run;

proc print data=want;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 2 replies
  • 967 views
  • 1 like
  • 3 in conversation