Hello, I am a fairly new SAS user and I am facing an issue with my code and/or the dataset I am working with.
When running a proc contents I have 5 variables that have a Type of Numeric, but the values taken on by these 5 variables are either Present, Absent, or . (missing). When I run the below code I get a clean log with no errors or warning messages; although all 8 variables output I only get one observation with all missing values ( . )
data redcap3;
array LN(*) acr_ii acr_iii acr_iv acr_v;
array Class(*) $ class_ii class_iii class_iv class_v;
do i = 1 to dim(LN);
class(i) = put(LN(i), $8.);
end;
drop i;
proc print;
run;
Does anyone know how to work with such variables? What steps do I need to take to change the variable type to character / or even code them as binary variables?
Any help is greatly appreciated!
Look at the formats assigned to the variables.
Can you please elaborate? Where would I go from there?
You likely have a format attached to the data.
Run a PROC CONTENTS and examine the output, specifically the type and format for your field of interest.
A format allows data to be numeric underneath, but it can be viewed with the description.
For example if you had a data set with Age, 1, 2,3 etc but wanted to see the numbers as One, Two, Three, you could use a format.
In the example below, I've created another age variable, identical the age value, but applied a format.
data class;
set sashelp.class;
age_numeric_format = age;
age_character = put(age, words.);
format age_numeric_format words.;
run;
title 'Demo of Formats';
proc print data=class;
run;
title 'Check formats and type for AGE variables';
proc contents data=class;run;
title;
You can remove a format from a variable to see the underlying values using a FORMAT statement:
data class_remove_formats;
set class;
format age_numeric_format ;*removes formats from age;
run;
title 'No format on age numeric format variable';
proc print data=class_Remove_formats;
run;
title;
Removing the formats is likely all you need/want to do.
format class_ii class_iii class_iv class_v;
@sassafras_ wrote:
Hello, I am a fairly new SAS user and I am facing an issue with my code and/or the dataset I am working with.
When running a proc contents I have 5 variables that have a Type of Numeric, but the values taken on by these 5 variables are either Present, Absent, or . (missing). When I run the below code I get a clean log with no errors or warning messages; although all 8 variables output I only get one observation with all missing values ( . )
data redcap3;
array LN(*) acr_ii acr_iii acr_iv acr_v;
array Class(*) $ class_ii class_iii class_iv class_v;
do i = 1 to dim(LN);
class(i) = put(LN(i), $8.);
end;
drop i;
proc print;
run;
Does anyone know how to work with such variables? What steps do I need to take to change the variable type to character / or even code them as binary variables?
Any help is greatly appreciated!
Thank you so much for the constructive feedback! I didn't realize it was so simple to remove formats.
This worked and I am able to move forward now. I greatly appreciate your help.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.