DATA Step, Macro, Functions and more

filtering a variable with Best12 format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

filtering a variable with Best12 format

If I am filtering a variable with numbers with a "Best12." format, does it matter whether I enclose the filter value in quotes?   In other words,

 

If [varname] = '20'

 

or

 

If [varname]=20

 

 


Accepted Solutions
Solution
‎04-18-2018 10:51 AM
Super User
Posts: 22,853

Re: filtering a variable with Best12 format

It didn't quite work, look at your log closely, specifically:

 

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

45:22

 

The general rule is don't have these in your log. 

If it works, why does it matter? 

Because then you can't tell the difference between a real error and where you made a decision to convert data.

View solution in original post


All Replies
Respected Advisor
Posts: 2,658

Re: filtering a variable with Best12 format

best is a numeric format, so you cannot use the quotes

--
Paige Miller
Occasional Contributor
Posts: 15

Re: filtering a variable with Best12 format

Posted in reply to PaigeMiller

That is what I assumed, but the character filter in line 45 below seems to work.   FYI, I'm asking this mundane question to document steps in a program.

 

 

30 data _null_;

31 set test1;

32 put termination_code;

33 run;

10

10

10

10

10

20

10

20

20

20

NOTE: There were 10 observations read from the data set WORK.TEST1.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

 

2 The SAS System 10:03 Wednesday, April 18, 2018

 

34

35 proc contents data=test1 noprint out=var_dat;

36 run;

NOTE: The data set WORK.VAR_DAT has 1 observations and 41 variables.

NOTE: PROCEDURE CONTENTS used (Total process time):

real time 0.04 seconds

cpu time 0.06 seconds

 

37

38 data _null_;

39 set var_dat(keep=NAME TYPE LENGTH FORMAT);

40 put _all_;

41 run;

NAME=Termination_Code TYPE=1 LENGTH=8 FORMAT=BEST _ERROR_=0 _N_=1

NOTE: There were 1 observations read from the data set WORK.VAR_DAT.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

42

43 data _null_;

44 set test1;

45 if termination_code='10' then put termination_code;

46 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

45:22

10

10

10

10

10

10

NOTE: There were 10 observations read from the data set WORK.TEST1.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

Solution
‎04-18-2018 10:51 AM
Super User
Posts: 22,853

Re: filtering a variable with Best12 format

It didn't quite work, look at your log closely, specifically:

 

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

45:22

 

The general rule is don't have these in your log. 

If it works, why does it matter? 

Because then you can't tell the difference between a real error and where you made a decision to convert data.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 82 views
  • 0 likes
  • 3 in conversation