DATA Step, Macro, Functions and more

Proc Freq-Help

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Proc Freq-Help


Hi,

I have a numeric variable which has values

1

2

.

i wrote the format

proc format;

value char

1="ONE"

2="TWO"  

<<<<<<<<<<<<<<<dint use anything for the .(missing value)

in the data step i used

Z=put(numeric variable,char.) so the values are converted to a charecter now

Now I am doing proc freq containing this variable and I dint want to get the missing(.)

So in the proc freq I use :

where (numeric variable) ne ".";

Even then the periood remains............

I had to go to the format and write other =" ";  to arrive at the result...Finally it gives Missing in the Contingency table at the bottom with out showing in the table itself...

Could somebody explain the logic behind????

Thanks a ton


Accepted Solutions
Solution
‎10-16-2012 01:30 AM
Super User
Posts: 10,041

Re: Proc Freq-Help

Posted in reply to robertrao

I think you mixed the missing value of both numeric and character.

where (numeric variable) ne .  ;

OR

where not missing(numeric variable) ;

Ksharp

View solution in original post


All Replies
Solution
‎10-16-2012 01:30 AM
Super User
Posts: 10,041

Re: Proc Freq-Help

Posted in reply to robertrao

I think you mixed the missing value of both numeric and character.

where (numeric variable) ne .  ;

OR

where not missing(numeric variable) ;

Ksharp

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

Thanks for the reply,

In the datastep i used a put function to apply the format above.

The format gets applied and . (missing stays as it is)

But the variable attributes is char now so i tried to use

where (numeric variable) ne" ." ;

Still missing appears in the 2*2 table..

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

Hi,

Another question is that

Can where clause be used with Numeric variable????What is in brackets is a numeric variable???can we use it???

where (numeric variable) ne .  ;

OR

where not missing(numeric variable) ;

Ofter times I get this Error: Where clause operator requires compatible variables!!!!

Thanks

Valued Guide
Posts: 634

Re: Proc Freq-Help

Posted in reply to robertrao

As Ksharp suggests I believe that you are confusing numeric and character missing values;

The numeric variable is not changed by the PUT function.  The new variable Z is character and the period (.) is no longer a missing value.

Is the following something like you are seeing (you did not show much code so I am guessing)?  Notice that the missing value for NUM is automatically excluded by FREQ (it is a classification variable), while Z has no missing values.

proc format;
value char
1="ONE"
2="TWO";

run;

data have;
input num;
z=put(num,char.);
datalines;
1
2
.
run;
proc freq data=have;
table num*z;
format num char.;
run;

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

Hi ,

Thanks for the detailed explanation.

I did not do it the way you showed me.

But in the format i wrote like this:

proc format;
value char
1="ONE"
2="TWO";

other=" "                         <<<<<<<--------------------

;

run;

But it took me a long time to figure this out....and got the missing(.) eliminated from the contingency table

So the other way is how you showed it above???

Thanks

Super User
Posts: 11,343

Re: Proc Freq-Help

Posted in reply to robertrao

Another way is before the data step using the put function set  Option missing=' '; The format approach is probably better most times but knowing about the option as an alternative is useful.

Also, remember to set mising back to '.' when done.

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

Hi ,

I also dint understand how the missing will be set back to "." after done????

Could you please show an example of the put function set  Option missing=' ';

Regards

Super User
Posts: 11,343

Re: Proc Freq-Help

Posted in reply to robertrao

The output for put statement or put function behaves the same with the option missing settings. Look in log for example 

data _null_;

x = .;

put 'Option missing=.' x;

run;

option missing=' '; /* set missing to blank*/

data _null_;

x = .;

put 'Option missing= blank' x;

run;

option missing='.'; /* reset to . when done */

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

hiiii,

After I run thwe complete program I get a 2*2 table with

num varaible having values ONE TWO

z variable having values  .   ONE TWO

                       NUM                  Z

                                             .        ONE      TWO

                       ONE             0          1            0    

                       TWO             0           0           1

How can i remove the . from Z now????I do not want it to be seen in the table!!!!

I guess THAT would be to use"

proc format;

value char

1="ONE"

2="TWO"

. =" "

;

RUN;

Any other methods....?????????

Valued Guide
Posts: 634

Re: Proc Freq-Help

Posted in reply to robertrao

Assuming that you are using the CHAR. format shown in your post (the version mapping . to ' ') (numeric missing to character missing), you should be seeing just the columns ONE and TWO for both NUM and Z.  PROC FREQ like other procedures that work with classification variables automatically exclude observations with classification variables (NUM and Z) that take on a missing value.

you could also apply a WHERE to subset the data by eliminating the missing values in an earlier step.

Super Contributor
Posts: 1,041

Re: Proc Freq-Help


Hi,

Thanks for the reply. Below in the format if I did not use . =" "  then I would be getting . in the cross tabulation table as shown above.

I want to clarify if adding . = " " in the format is the only way to get rid of the . from the z variable(char variable) during cross tabulation?

proc format;

value char

1="ONE"

2="TWO"

. =" "   <<<<<<<<<<<-------------------------if i did not use this

;

RUN;

can i also do this;

proc freq data=have;

where z ne "." ;          /*assuming I dint use . = " " in the proc format*/

table num*z;

format num char.;

run;

Regards

Valued Guide
Posts: 634

Re: Proc Freq-Help

Posted in reply to robertrao

You could filter for the '.' using a WHERE.  However you will also need to use a LEFT function to eliminate leading blanks.  The period is actually being stored with two leading blanks.

proc freq data=have(where=(left(z) ne '.'));

Super Contributor
Posts: 1,041

Re: Proc Freq-Help

Hi,

Tried and tested it. Great help. Thanks for the in depth  explanation....

Regards

🔒 This topic is solved and locked.

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

Discussion stats
  • 13 replies
  • 780 views
  • 7 likes
  • 4 in conversation