Hello,
I am trying to modify the formatting for variables in SAS 9.4 using 'proc format'. An example is the variable "sCYSleep" which ranges from 0-16. I am trying to create groups (as in the picture) with these values. When running frequency tables right after assigning formatting, I get the respective groups. However, whenever I run subsequent analysis, my sCYSleep variable takes on it's original 0-16.
Is there a way it can retain the formatted groupings? I'd like to have those in the dataset. I tried to manually change the values and SAS scrambles the order. Is there a way to also preserve the natural ordering of the variable names?
I think it would work if you apply the format in a data step instead of inside proc freq. The format inside proc freq, I think, would only be held within that running of the procedure. Doing it in a data step will apply the format "permanently" (i.e. in subsequent analytic steps, like proc freq).
data work.val; set work.val;
format sleepvar fmt.;
run;
Hej,
Permanent Informats and Formats
If you want to use a format or informat that is created in one SAS job or session in a subsequent job or session, then you must permanently store the format or informat in a SAS catalog.
You permanently store informats and formats by using the LIBRARY= option in the PROC FORMAT statement.
See the discussion of the LIBRARY= option in the PROC FORMAT Statement.
Also in doc :
Koen
That should work for you.
Reeza,
Thank you for this solution!
Do you know how to tell SAS to keep the categories in order (i.e., none, low, etc.). When I run frequency tables pr any subsequent stats, the categories are all jumbled up. It appears to be listed in alphabetical order (i.e., high, low, etc.).
Reeze are you studying sleep probs again? You're going to make a helpful accident, which you do every time!
"Natural ordering of the variable names"?
What does that mean?
If you make a new variable it will naturally be added after all of the existing variables.
If you convert a number to a character string it will naturally sort differently. If you want the text values to sort in the same order as the original numeric values then you will need to be more creative in the strings you using. Perhaps add a prefix to the strings?
@ValSki wrote:
Hi Tom,
I meant to preserve the hierarchical nature of the original variable names (i.e., none; low; moderate, etc.).
I can preserve the ordering if I use the original variable name with the formatting applied. That seemed to have solve the problem of alphabetical ordering.
So your did not mean variable names. Your variable name is SCYSLEEP.
You are talking about VALUES not NAMES. In particular the displayed values. So either the formatted values of your existing numeric variable or the values stored into your new character variable.
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!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.