DATA Step, Macro, Functions and more

proc format invalue

Accepted Solution Solved
Reply
Valued Guide
Posts: 858
Accepted Solution

proc format invalue

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. 


Accepted Solutions
Solution
‎01-13-2017 02:00 PM
PROC Star
Posts: 7,356

Re: proc format invalue

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


All Replies
Solution
‎01-13-2017 02:00 PM
PROC Star
Posts: 7,356

Re: proc format invalue

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

 

Super User
Posts: 17,730

Re: proc format invalue

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 152 views
  • 1 like
  • 3 in conversation