I give up, this one doesn't make sense to me. I have a variable in a dataset that is all missing.
I need it to recode to 99, the code for does not collect. I've tried a number of variations.
Dropping the variable beforehand and then adding it back, If/Then logic. Everything keeps generating * when I run a proc freq.
Here's my basic code:
data want;
set have;
variable = 99;
run;
Well that's probably it, it's a character variable.
I will try to get you the log on that, but I have to clean up the log a bit first.
I think this is the code you're wanting from the Log Reeza.
NOTE: There were 69871 observations read from the data set WORK.MODIFY.
NOTE: The data set WORK.MOD2 has 69871 observations and 186 variables.
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted
by the "BEST" format.
NOTE: DATA statement used (Total process time):
real time 0.27 seconds
cpu time 0.23 seconds
There is not formatting applied in the creation of this one.
Here is what I get when I run the contents:
HSMRNT_PRVD_TP | Char | 1 | $1. | $1. |
That shows that your variable does have the $1 format attached, as Tom predicted. Please see above suggestions from Tom and me about how to remove the format.
So you have a character variable that is only one byte long. There is no way to store the two byte string '99' into that variable.
You will need to make a NEW variable to change the length (or at least define the length before referencing the old variable via the SET statement).
What value is it that you want to change to '99'? If cannot be a numeric missing value since the variable is character and not numeric.
And also (perhaps actually most importantly) why would you WANT to convert a missing value to a non-missing value? If you did make the variable numeric then storing 99 instead of . (or any of the other 27 special missing values) would make using variable HARDER. You could not use MAX or MIN or MEAN or other statistical operations on it without first eliminating the 99's.
Is it possible you created this dataset by using PROC IMPORT? That procedure when reading from a text file or an Excel file will define any variable with all missing values as character with a length of 1 since that takes less space to store than a number.
Since you mention PROC freq, check that you don't have a format changing the value displayed.
proc freq data=want;
tables variable;
format variable; *remove any format attached;
run;
@DanielQuay wrote:
I give up, this one doesn't make sense to me. I have a variable in a dataset that is all missing.
I need it to recode to 99, the code for does not collect. I've tried a number of variations.
Dropping the variable beforehand and then adding it back, If/Then logic. Everything keeps generating * when I run a proc freq.
Here's my basic code:
data want;
set have;
variable = 99;
run;
Show us the results of Proc Contents for your Have data set. That will help reduce the number of things that we have to guess at. NOT the Want data set, the HAVE, though if the code is as you show there really shouldn't be much difference.
Check what display format you have attached to the variable.
I can recreate what you seem to be describing by just attaching a format that uses a width that is too small to display 99.
data test;
variable=99;
format variable 1.;
run;
proc freq data=test;
tables variable;
run;
The FREQ Procedure Cumulative Cumulative variable Frequency Percent Frequency Percent ------------------------------------------------------------- * 1 100.00 1 100.00
Note that most SAS variables do NOT need to have a format attached. The exception is DATE, TIME and DATETIME values that are hard for humans to understand without using a format to display them. If you want to just remove the formats from a variable (or multiple variables) then use a FORMAT statement that lists variables but does not include any format specification after the list. You can use the _ALL_ keyword to remove the formats from ALL of the variables. You could then add a second format statement to add back any formats that are needed.
format _all_ ;
format datevar date9.;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.