BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

Data ICPNEED.data_carerecipients;
Set ICPNEED.data_trim4;
edu_numeric = edu + 0;
If marriage = 1 then cr_marital = 'Married';
Else
if marriage = 2 then cr_marital = 'Not married';
Else
if marriage = 3 then cr_marital = 'Not married';
Else
if marriage = 4 then cr_marital = 'Not married';
Else
if marriage = 5 then cr_marital = 'Not married';
Else
if marriage = . then cr_marital = " ";
if iadl_income_3 = 1 then iadl_income_3rc = '$0-$10,999';
Else if iadl_income_3 = 2 then iadl_income_3rc = '$11,000-$14,999';
if iadl_income_3 = 3 then iadl_income_3rc = '$15,000-$24,999';
Else if iadl_income_3 = 4 then iadl_income_3rc = '$25,000-$34,999';
if iadl_income_3 = 5 then iadl_income_3rc = '$35,000-$49,999';
Else if iadl_income_3 = 6 then iadl_income_3rc = '$50.000-$74,999';
if iadl_income_3 = 7 then iadl_income_3rc = '$75,000-$99,999';
Else if iadl_income_3 = 8 then iadl_income_3rc = '$100,000-or more';
if iadl_income_3 = . then iadl_income_3rc = " ";

Format race fmtrace. current_living_dich fmtcurrent_living_dich. sex fmtsex.;
Label
cr_marital = "Care Recipient Marital Status"
current_living_dich = "Current living situation"
edu_numeric = "Care Recipient Education"
iadl_income_3rc = "Care Recipient Household Income";
run;

Proc sort data = ICPNEED.data_carerecipients;
by iadl_income_3rc;
Run;

Proc freq data = ICPNEED.data_carerecipients;
Tables race sex current_living_dich cr_marital iadl_income_3rc;
Run;

 

gtucke1_0-1653140424028.png

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

It would help if you explained what is wrong. Showing us code and output without explanation of what is wrong makes it impossible for us to help. (And this applies not just to this problem but to all requests for help from you in the future)

--
Paige Miller
gtucke1
Fluorite | Level 6

The problem is that the table is not displaying the entire value such as $0-$10,999, $11,000- $14,000 etc.

PaigeMiller
Diamond | Level 26

@gtucke1 wrote:

The problem is that the table is not displaying the entire value such as $0-$10,999, $11,000- $14,000 etc.


As stated by @Kurt_Bremser (twice) you want to use custom formats, not character strings. Formats of a numeric variable will sort numerically and the values don't get chopped off. Character variables, like the ones you created, will sort alphabetically, which seems to be a bad thing here and values get chopped off if you don't do it properly.

 

proc format;
    value marital 1='Married' 2,3,4,5='Not Married' .=' ';
    value income 1='$0-$10,999' 2='$11,000-$14,999' /* You type the rest */ ;
run;
proc freq data=ICPNEED.data_carerecipients;
    table iadl_income_3 marriage/missing;
    format iadl_income_3 income. marriage marital.;
run;

 

--
Paige Miller
Kurt_Bremser
Super User

You are much better off defining formats for your values and using them in the FREQ procedure. FREQ will group on formatted values automatically, and keep the correct order (in your data, the highest group comes immediately after the lowest, because "$100.000" is "lower" than "$11.000".

I showed you the usage of formats here: https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/td... 

Your truncated values happen because the first assignment of '$0-$10,999' defines the length of the variable. See Maxim 47. This is automatically prevented by using a format.

Tom
Super User Tom
Super User

The table (aka the report) is showing the entire value.

But you tried to assign values to a variable that were longer than the length you defined for the variable.

 

Note that if you don't define the length of a variable before using it SAS will GUESS what length to use based on how you first use the variable in your code.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 596 views
  • 0 likes
  • 4 in conversation