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

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.

 

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
  • 385 views
  • 1 like
  • 3 in conversation