BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

I've run the following code and keep receiving an error that crgender is uninitialized. 

 

I ran the following:

Data ICPNEED.data_carerecipients;
Set work.original_final;
run;

Proc Format;

Value fmtsex
0 = 'Male'
1 = 'Female';

Value fmtrace 1 = 'White'
2 = 'Black'
3 = 'Asian'
4 = 'Other';

Value fmtcurrent_living_dich
0 = 'Living Alone'
1 = 'Living with ICP or Others';
Run;

Data ICPNEED.data_CRdemo;
Set ICPNEED.data_carerecipients;
edu_numeric = edu + 0;
if cg_relation___1 = 1 then cg_relationrc = 'Spouse/Partner';
else if cg_relation___2 = 1 then cg_relationrc = 'Brother/Sister';
else if cg_relation___3 = 1 then cg_relationrc = 'Child;';
else if cg_relation___4 = 1 then cg_relationrc = 'Friend';
else if cg_relation___5 = 1 then cg_relationrc = 'Grandchild';
else if cg_relation___6 = 1 then cg_relationrc = 'Paid CG';
else if cg_relation___7 = 1 then cg_relationrc = 'Other';
else if cg_relation____8 = 1 then cg_relationrc = ' ';
else if cg_relation____9 = 1 then cg_relationrc = ' ';
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 = " ";

Format race fmtrace. current_living_dich fmtcurrent_living_dich. crgender 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"
mmse_total_score = "Mini Mental State Exam"
pgdrs_tot = "Psychogeriatric Dependency"
npi_fs_tot = "Neuropsychiatric Invnetory"
npi_dist_tot = "Neurospychiatric Invntory Distress"
qolad_p_tot = "Quality of Life with AD self report CR"
qolad_sp_tot = "Quality of Life with AD reported by ICP"
Katz_adl_tot = "Katz Index of Independence of Daily Living"
cg_relationrc = "ICP Relationship to Care Recipient"
race = "CR Race"
sex = "CR Gender"
age = "CR Age";
run;

 

After I run this, if I go back up and run the following:

 

Data ICPNEED.data_CRdemo;
Set ICPNEED.data_carerecipients;
Run;

Proc freq data = ICPNEED.data_CRdemo;
Table sex;
Run;

 

I get this table:

 

gtucke1_1-1653581222296.png

 

Proc freq data = ICPNEED.data_CRdemo;
Tables race crgender current_living_dich cr_marital cg_relationrc;
Run;

 

This is the table I get for crgender:

 

gtucke1_2-1653581257385.png

 

 

 

 

 

 

 

 

 

5 REPLIES 5
AMSAS
SAS Super FREQ

Can you post the SAS log, and please use the Blockquote (or Insert SAS code) formatting option in the menu bar below Body and above this text entry field
Thanks

Tom
Super User Tom
Super User

Follow the data.

Step one copy work.original_final -> ICPNEED.data_carerecipients

Step two copy ICPNEED.data_carerecipients ->  ICPNEED.data_CRdemo with some changes.

Step three copy ICPNEED.data_carerecipients -> ICPNEED.data_CRdemo but WITHOUT the changes.
Step four use that second version of ICPNEED.data_CRdemo to reference a variable named SEX.

Step five use that second version of ICPNEED.data_CRdemo to reference CRGENDER and other variables.

 

At no place do you have any code to create CRGENDER.  So for it to exist in that second version of ICPNEED.data_CRdemo it would have needed to exist in the work dataset ORIGINAL_FINAL from your first session.   

 

Where is the code that create that WORK.ORIGINAL_FINAL dataset in the first SAS session?

Reeza
Super User

@gtucke1 wrote:

 

After I run this, if I go back up and run the following:

 

Data ICPNEED.data_CRdemo;
Set ICPNEED.data_carerecipients;
Run;

 

 


This erases all the work in the previous step (below). Why are you doing this step, what do you think it accomplishes?

 


@gtucke1 wrote:

I've run the following code and keep receiving an error that crgender is uninitialized. 

 

I ran the following:

Data ICPNEED.data_carerecipients;
Set work.original_final;
run;

Proc Format;

Value fmtsex
0 = 'Male'
1 = 'Female';

Value fmtrace 1 = 'White'
2 = 'Black'
3 = 'Asian'
4 = 'Other';

Value fmtcurrent_living_dich
0 = 'Living Alone'
1 = 'Living with ICP or Others';
Run;

Data ICPNEED.data_CRdemo;
Set ICPNEED.data_carerecipients;
edu_numeric = edu + 0;
if cg_relation___1 = 1 then cg_relationrc = 'Spouse/Partner';
else if cg_relation___2 = 1 then cg_relationrc = 'Brother/Sister';
else if cg_relation___3 = 1 then cg_relationrc = 'Child;';
else if cg_relation___4 = 1 then cg_relationrc = 'Friend';
else if cg_relation___5 = 1 then cg_relationrc = 'Grandchild';
else if cg_relation___6 = 1 then cg_relationrc = 'Paid CG';
else if cg_relation___7 = 1 then cg_relationrc = 'Other';
else if cg_relation____8 = 1 then cg_relationrc = ' ';
else if cg_relation____9 = 1 then cg_relationrc = ' ';
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 = " ";

Format race fmtrace. current_living_dich fmtcurrent_living_dich. crgender 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"
mmse_total_score = "Mini Mental State Exam"
pgdrs_tot = "Psychogeriatric Dependency"
npi_fs_tot = "Neuropsychiatric Invnetory"
npi_dist_tot = "Neurospychiatric Invntory Distress"
qolad_p_tot = "Quality of Life with AD self report CR"
qolad_sp_tot = "Quality of Life with AD reported by ICP"
Katz_adl_tot = "Katz Index of Independence of Daily Living"
cg_relationrc = "ICP Relationship to Care Recipient"
race = "CR Race"
sex = "CR Gender"
age = "CR Age";
run;

 

 

 


 

PaigeMiller
Diamond | Level 26

When there is something in the log indicating a problem, you should ALWAYS show us the ENTIRE log for the PROC or DATA step that has the problem. Emphasis on ENTIRE, do not show us selected parts. Copy the log as text, and paste it into the window that appears when you click on the </> icon.

 

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

 

I believe your problem is here:

 

Format race fmtrace. current_living_dich fmtcurrent_living_dich. crgender fmtsex.;

There is no variable named CRGENDER in the data set ICPNEED.data_carerecipients and also a variable by that name is not created in the DATA step that contains that format statement.

 

 

--
Paige Miller
ballardw
Super User

In this block of code please look at the two pieces highlighted in red. I suspect that instead of applying a format to CRGENDER you meant to use the variable SEX since it's label is like the name of that variable that does not exist. That message quite often comes from using the incorrect name of a variable such as misspelling but in this case I think it is a bit broader of simple wrong variable name in code.

Format race fmtrace. current_living_dich fmtcurrent_living_dich. crgender 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"
mmse_total_score = "Mini Mental State Exam"
pgdrs_tot = "Psychogeriatric Dependency"
npi_fs_tot = "Neuropsychiatric Invnetory"
npi_dist_tot = "Neurospychiatric Invntory Distress"
qolad_p_tot = "Quality of Life with AD self report CR"
qolad_sp_tot = "Quality of Life with AD reported by ICP"
Katz_adl_tot = "Katz Index of Independence of Daily Living"
cg_relationrc = "ICP Relationship to Care Recipient"
race = "CR Race"
sex = "CR Gender"

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 515 views
  • 2 likes
  • 6 in conversation