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;
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.
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.
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.
@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.
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.
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.
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.
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.
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 |
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)
here the proc contents result on these two vars.
Alphabetic List of Variables and Attributes | |||||
Variable | Type | Len | Format | Informat | Label |
NUM_PRT_3M | Char | 1 | |||
gender_sp | Char | 2 | gender_sp |
I renamed gendersp var to gender_sp. is that what?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.