BookmarkSubscribeRSS Feed
sassafras_
Fluorite | Level 6

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!

 

 

4 REPLIES 4
sassafras_
Fluorite | Level 6

Can you please elaborate? Where would I go from there? 

 

 

Reeza
Super User

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!

 

 


 

sassafras_
Fluorite | Level 6

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 404 views
  • 1 like
  • 3 in conversation