10-16-2012 01:17 AM
I have a numeric variable which has values
i wrote the format
<<<<<<<<<<<<<<<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
10-16-2012 01:42 AM
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..
10-17-2012 12:22 AM
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 . ;
where not missing(numeric variable) ;
Ofter times I get this Error: Where clause operator requires compatible variables!!!!
10-16-2012 02:07 AM
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 freq data=have;
format num char.;
10-16-2012 09:58 AM
Thanks for the detailed explanation.
I did not do it the way you showed me.
But in the format i wrote like this:
other=" " <<<<<<<--------------------
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???
10-16-2012 10:13 AM
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.
10-16-2012 10:22 AM
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=' ';
10-16-2012 10:32 AM
The output for put statement or put function behaves the same with the option missing settings. Look in log for example
x = .;
put 'Option missing=.' x;
option missing=' '; /* set missing to blank*/
x = .;
put 'Option missing= blank' x;
option missing='.'; /* reset to . when done */
10-16-2012 11:35 PM
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
. 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"
. =" "
Any other methods....?????????
10-17-2012 12:48 PM
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.
10-17-2012 01:09 PM
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?
. =" " <<<<<<<<<<<-------------------------if i did not use this
can i also do this;
proc freq data=have;
where z ne "." ; /*assuming I dint use . = " " in the proc format*/
format num char.;
10-17-2012 01:54 PM
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 '.'));
Need further help from the community? Please ask a new question.