BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

good afternoon,

please tell what is wrong wit this code.

DATA STDTELMT.MERGED_I1;
SET STDTELMT.MERGED_I;
IF SEX_WITH_MALE="1" THEN GENDER_SP="1";
IF SEX_WITH_MAN="1" AND SEX_W_MALE="0" THEN GENDER_SP="1";
IF SEX_W_FEMALE="1" THEN GENDER_SP="2";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="3";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="1" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="3";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="1" AND SEX_W_TRANSGENDER="1" THEN GENDER_SP="3";
IF SEX_W_FEMALE="0" AND SEX_WITH_MALE="0" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="9";
IF SEX_W_FEMALE="0" AND SEX_WITH_MALE="0" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="1" THEN GENDER_SP="9";
RUN;

 

/*CHECKING TO SEE IF THE CODE ABOVE WORKED*/
PROC FREQ DATA=STDTELMT.MERGED_I1;
TABLE GENDER_SP;
RUN;

 

it only created this table.


The FREQ Procedure
GENDER_SP Frequency Percent CumulativeFrequency CumulativePercent1Frequency Missing = 3602
1529100.001529100.00
4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

What does your log say? Does the code generate an error?

noling
SAS Employee

If your syntax is correct then this is probably a logic issue and there are records that don't match any of your criteria. You could look at your output STDTELMT.MERGED_I1 table for records without a GENDER_SP value, then troubleshoot. 


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

Dhana18
Obsidian | Level 7
Thank you! It was like what you said.
ballardw
Super User

@Dhana18 wrote:

good afternoon,

please tell what is wrong wit this code.

DATA STDTELMT.MERGED_I1;
SET STDTELMT.MERGED_I;
IF SEX_WITH_MALE="1" THEN GENDER_SP="1";
IF SEX_WITH_MAN="1" AND SEX_W_MALE="0" THEN GENDER_SP="1";
IF SEX_W_FEMALE="1" THEN GENDER_SP="2";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="3";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="1" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="3";
IF SEX_W_FEMALE="1" AND SEX_WITH_MALE="1" AND SEX_W_MAN="1" AND SEX_W_TRANSGENDER="1" THEN GENDER_SP="3";
IF SEX_W_FEMALE="0" AND SEX_WITH_MALE="0" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="0" THEN GENDER_SP="9";
IF SEX_W_FEMALE="0" AND SEX_WITH_MALE="0" AND SEX_W_MAN="0" AND SEX_W_TRANSGENDER="1" THEN GENDER_SP="9";
RUN;

 

/*CHECKING TO SEE IF THE CODE ABOVE WORKED*/
PROC FREQ DATA=STDTELMT.MERGED_I1;
TABLE GENDER_SP;
RUN;

 

it only created this table.


The FREQ Procedure
GENDER_SP Frequency Percent CumulativeFrequency CumulativePercent1Frequency Missing = 3602
1529 100.00 1529 100.00

If you run the following code it will show all of the assignment combinations of the variable and the independent variables.

proc freq data=stdtelmt.merged_i1;
   tables  SEX_WITH_MALE*SEX_WITH_MAN* SEX_W_FEMALE*SEX_W_MAN*SEX_W_TRANSGENDER*GENDER_SP
          /list missing;
run;

 My suspicion involves either missing values for like named variables SEX_WITH_MALE and SEX_W_MAN plus use of "AND" where likely OR was needed.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 869 views
  • 0 likes
  • 4 in conversation