Dear SAS users,
I have studied the informat topic and used the INPUT() function to change a character variable (STDs:Year_since_first_diagnosis) into a numeric (STD_1stDx). The outcome of the execution of code is shown below. However, the outcome of the numeric STD_1stDx contains no observation at all. Initially, I thought the BEST.w format is incorrect, but the missing observation is still persist even after I have changed it from best4. to best12..
Data work.cervical_cancer_t2;
set work.import;
STD_1stDx = input('STD:Year_since_first_diagnosis', best4.);
RUN;
My main concerns are:
(1) I am still confused about the proper usage of BEST.w in this case for converting character to numeric and vice versa.
(2) What steps can I do now to get the proper observation in the STD_1stDx, so that I can first perform descriptive analysis and subsequently deal with the missing values?
I have attached the excel file for the output of the observation, and the output of the compiled Proc Contents.
Thank you so much.
Missed something from your post...the content perhaps?
You're missing just a single character: n
If you have a variable named STD:Year_since_first_diagnosis, you have to refer to that variable as:
'STD:Year_since_first_diagnosis'n
You could then simplify and change best4. to just plain 4. instead.
One of the reasons why 'some crap'n variable names should (IMO must) not be used.
In your code, you tried to use a non-standard SAS name, but failed to append the n after the name string:
STD_1stDx = input('STD:Year_since_first_diagnosis', best4.);
it should have been
STD_1stDx = input('STD:Year_since_first_diagnosis'n, best4.);
So a very little omission (that doesn't even cause a syntax ERROR message!) caused missing values, because SAS tried to convert the string 'STD:Year_since_first_diagnosis' to numeric instead of the contents of the variable named STD:Year_since_first_diagnosis.
By using standard valid SAS names, one is notfied of a typo immediately because a string without quotes HAS to be a variable name.
Just to add, having '<string>'n is called named literals and it is a method of refering to external files/databases which allow for variable names to not conform to SAS standards, typically when using an Excel file you will see this as Excel allows anything in its cells. For normal programm activities it is better to import the data intoa dataset, and then use the actual names of variables rather than keep refering to the named literals as this both makes your code simpler, easier to read, and avoids these complications arising from the use of named literals.
The X in bestX. refers to the maximum length of the item (for numerics it includes the . if present) so best4. could be:
123
1.23
12.3
Without knowing your data we cannot possible tell you what format best applies to the data only you can see or know about.
I would also suggest running through the tutorials and such like that SAS provide as this is a basic fundamental of SAS:
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.