BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Good morning,
the new vari i am trying to create MENSEX did not create. What is wrong with this code below?

DATA NovDec19.MERGED_NUMPARTS_1;
length mensex $3;
SET NovDec19.MERGED_NovDec19_NUMPARTS;
if gender_sp ="1" AND NUM_PRT_3M="1" THEN MENSEX= "1";
if gender_sp ="1" AND NUM_PRT_3M="2" THEN MENSEX="2";
if gender_sp ="1" AND NUM_PRT_3M="3" THEN MENSEX="3";
if gender_sp ="1" AND NUM_PRT_3M="5" THEN MENSEX="5";
if gender_sp in("3" , "9") AND NUM_PRT_3M in("1" , "2" , "3" , "5") THEN MENSEX="999";
run;
19 REPLIES 19
ballardw
Super User

Did you look at the log after running the code? If there were any notes about variables not found, not referenced or data conversions that could be one cause. Post a copy of the log from running the if there are any messages of such type.

 

Otherwise we would need example data. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

The example data only needs to include the variables you show being used in your code.

Dhana18
Obsidian | Level 7
Here is the log:
DATA NovDec19.MERGED_NUMPARTS_1;
3 length mensex $3;
4 SET NovDec19.MERGED_NovDec19_NUMPARTS;
5 if gender_sp ="1" AND NUM_PRT_3M="1" THEN MENSEX= "1";
6 if gender_sp ="1" AND NUM_PRT_3M="2" THEN MENSEX="2";
7 if gender_sp ="1" AND NUM_PRT_3M="3" THEN MENSEX="3";
8 if gender_sp ="1" AND NUM_PRT_3M="5" THEN MENSEX="5";
9 if gender_sp in("3" , "9") AND NUM_PRT_3M in("1" , "2" , "3" , "5") THEN MENSEX="999";
10 run;

NOTE: There were 995 observations read from the data set NOVDEC19.MERGED_NOVDEC19_NUMPARTS.
NOTE: The data set NOVDEC19.MERGED_NUMPARTS_1 has 995 observations and 203 variables.
NOTE: DATA statement used (Total process time):
real time 0.59 seconds
cpu time 0.12 seconds

Dhana18
Obsidian | Level 7

Hello, than you for your email. the instructions is too comlicated forme. Would be nic eot have a simple instructions. sorry it was not so helpful for me this time.

Dhana18
Obsidian | Level 7

Hi All,

I am not getting answers to my problem questions as I did in the past. Did something change in the system? Am I not asking question the right way?  Did I do something wrong? Do people not want to help me?

Please help me I need your help to do my job well.

thank you.

Tom
Super User Tom
Super User

@Dhana18 wrote:

Hi All,

I am not getting answers to my problem questions as I did in the past. Did something change in the system? Am I not asking question the right way?  Did I do something wrong? Do people not want to help me?

Please help me I need your help to do my job well.

thank you.


Are you referring to this thread?  Did you try the things suggested?  Did they make a difference?

Note that if you do not provide a minimal complete set of data and code that re-creates the problem then all you get is suggestions, since the people replying will have nothing to test their suggestions against.

PaigeMiller
Diamond | Level 26

As stated by @ballardw: "One thing that we learn eventually about SAS is that it tries to help us make "nice" output. Sometimes that interferes with diagnosing problems when using output from procedures to examine values." You need to provide us with the data set, in the format that we have requested, and then we ought to be able to provide help. That seems to be the only path forward — showing us the data in other forms, as you have done, which can disguise the true cause of the matter, doesn't lead to any obvious answers.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Since we don't have the data set NovDec19.MERGED_NovDec19_NUMPARTS, you need to look at this data set and see what values are present for variables gender_sp and NUM_PRT_3M.


Also, please look at the log for ERROR or WARNING messages.

--
Paige Miller
Dhana18
Obsidian | Level 7
Table of NUM_PRT_3M by gender_sp

NUM_PRT_3M

gender_sp(gender_sp)

1

2

3

9

Total

0

128


193


17


44


382


1

128


144


4


3


279


2

70


107


13


3


193


3

8


57


11


0


76


5

16


40


6


3


65


Total

350


541


51


53


995



PaigeMiller
Diamond | Level 26

Yes, I see the numbers, but I wanted you to look at the the actual SAS dataset used (not me look at something you typed) and see if the values in each row of your dataset should produce the values of MENSEX based upon the code you showed us. I cannot tell, because I don't have the data set, you do.

--
Paige Miller
ballardw
Super User

That 'table' isn't legible.

 

Try running this code on your data:

proc freq data= NovDec19.MERGED_NUMPARTS_1;
   tables  gender_sp* NUM_PRT_3M*MENSEX / missing list nopercent nocum;
run;

This will show all of the combinations of the three variables present in your data, include MISSING values, in an easier to read row layout. So you may find combination that you did not consider for your recoding.

Dhana18
Obsidian | Level 7
gender_sp NUM_PRT_3M mensex Frequency 1 0 999 128 1 1 999 128 1 2 999 70 1 3 999 8 1 5 999 16 2 0 999 193 2 1 999 144 2 2 999 107 2 3 999 57 2 5 999 40 3 0 999 17 3 1 999 4 3 2 999 13 3 3 999 11 3 5 999 6 9 0 999 44 9 1 999 3 9 2 999 3 9 5 999 3 I want this to be like this gender_sp NUM_PRT_3M mensex Frequency 1 0 999 128 1 1 1 128 1 2 1 70 1 3 1 8 1 5 1 16 2 0 999 193 2 1 1 144 2 2 2 107 2 3 3 57 2 5 5 40 3 0 999 17 3 1 1 4 3 2 2 13 3 3 3 11 3 5 5 6 9 0 999 44 9 1 1 3 9 2 2 3 9 5 5 3
Dhana18
Obsidian | Level 7
gender_spNUM_PRT_3MmensexFrequency
10999128
11999128
1299970
139998
1599916
20999193
21999144
22999107
2399957
2599940
3099917
319994
3299913
3399911
359996
9099944
919993
929993
959993
PaigeMiller
Diamond | Level 26

Are the variables GENDER_SP and NUM_PRT_3M formatted somehow?

 

Please show us a PROC CONTENTS of this data set (well, we really need to see just those two variables from the PROC CONTENTS output)

--
Paige Miller
Dhana18
Obsidian | Level 7

here the proc contents result on these two vars.

Alphabetic List of Variables and Attributes
VariableTypeLenFormatInformatLabel
NUM_PRT_3MChar1   
gender_spChar2  gender_sp

I renamed gendersp var to gender_sp. is that what?

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
  • 19 replies
  • 804 views
  • 1 like
  • 4 in conversation