I am using an existing dataset to create a bunch of new variables, all to make one final variable. I have that final variable in a continuous form (jointyears), and I want to make it categorical (jointyears_cat). I've used if/then statements to do so. However, the log is telling me when I run the if/then statements, that the categorical variable, jointyears, is uninitialized, even though I created it immediately before and included a data and a set statement. I also ran a proc contents for work.adenovar and work.adeno1, and in each the variables that I need/are coding with are all present. Here is my code/log:
If you are using 99 for the variables to indicate "value not recorded" "value out of range" "not valid" "not available" or any related idea that it should never be used for calculation then you may want to consider learning that SAS has a concept of "missing value". By default missing values are not used for most calculations.
This can potentially save you a LOT of "and thisvar ne 99 and thatvar ne 99 and othervar ne 99" type code. (I use ne instead of ^= because it is easier to type). Example:
data example; input hashtot hashlage1 hashfage1 ; if hashtot >= 1 and hashtot < =4 then hashdur1 = (hashlage1-hashfage1)+1; datalines; 0 3 4 1 2 3 1 . 17 1 1 . 1 . . ; proc print; run;
The missing values are also excluded for summary statistics purposes:
proc means data=example n max min mean median; var hashtot hashlage1 hashfage1; run;
Naming every variable with a prefix like "hash" may be counter productive in that is 4 extra characters you have to type all the time.
That many variables with suffixes makes me suspect that you may have a poor data structure and that is causing lots of repetitive code for the same variable meaning. Typically this occurs when translating a process from spreadsheet thinking.
Thank you for the reply, even though it is not at all related to the question I asked. I am fully aware that SAS has a concept of "missing value," as you put it, and that 99 is not used in calculations. I wrote my code to ensure those observations were excluded. I'm not sure how you came to those conclusions about my use of 99, as I gave very little information about my dataset. Following this, you literally have no information about my dataset, the size of it, or what I'm using it for, so I would refrain from telling me how I should name my variables, and declaring that I have poor data structure. Next time, try answering the questions that people ask. Have a good one!
@gejoachim99 wrote:
Thank you for the reply, even though it is not at all related to the question I asked. I am fully aware that SAS has a concept of "missing value," as you put it, and that 99 is not used in calculations. I wrote my code to ensure those observations were excluded. I'm not sure how you came to those conclusions about my use of 99, as I gave very little information about my dataset. Following this, you literally have no information about my dataset, the size of it, or what I'm using it for, so I would refrain from telling me how I should name my variables, and declaring that I have poor data structure. Next time, try answering the questions that people ask. Have a good one!
We have a lot people on this forum just learning SAS. The number of posts you have made does not indicate any great experience with SAS so helpful hints should be considered before getting upset. I reached the consideration about possibly using 99 as missing data because 1) you were excluding that value from calculation for multiple variables and 2) 99, 999, 9999 and similar values have been used as "special values" for a very long time and often in languages that do not have a concept like "missing" requiring use of many explicit "if" clauses to work around them.
I note that you do not say anything that your data or process did not derive from a spreadsheet anywhere though.
I can also tell that you are potentially mangling some date related values (365.25 is NOT exactly one year), are unfamiliar with arrays (which would likely reduce all of the hashnumx code by a lot), don't care to use proper variable types (creating a bunch of "day" variables as character and then immediately using them in arithmetic) and could quite possibly use some experience with Formats to avoid that second data step entirely.
My only point is that you did not answer the question I asked. While I only have started using this forum recently, I have been using SAS for years now. You also have no idea the PURPOSE of my coding, so I am again confused about how exactly you are coming to the conclusion you are. I would implore you to not make such assumptions. Lastly, I assure you, I would take what you had written into consideration without getting "upset," as you insist I am, if you would attempt to help in a less condescending and uninformed way.
These forums have participants who are SAS employees, but most participants are non-SAS volunteers. You have no standing to specify what kind of help you are going to get.
I agree with ballardw's comments on your code. They do make the unwarranted assumption that you are interested in making your code easier to read and debug, but even if that is not your goal, it might be the goal of other people who read the messages here. As of this writing, 140 people have looked at this message thread, and some of them might find ballardw's advice useful. They might be newcomers who haven't yet learned that dividing by 365.25, or even 365.2422, is not the best way in SAS to calculate years, or that coding 99... is not the best way to represent unknown values in SAS (and for that matter, was probably never the best choice in any language when dealing with non-trivial data domains).
I see your point. In that case, I truly hope that users insulting my code will be helpful to others.
To all involved, you can click on someone's name and then click Ignore. It's a great feature that I've started using to protect my time and sanity.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.