BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FreelanceReinh
Jade | Level 19

I assume that you replaced my guessed dummy names dx1, dx2, icdcode_BL by your variable names before running the PROC PRINT step (otherwise, you'd have received error messages like "ERROR: Variable DX1 not found." and not even missing values).

 

Thanks for the important information that the variables are numeric. Hence, you cannot apply a character function such as SUBSTR to these variables. Did the PROC CONTENTS output contain a column headed "Format"? If yes, what did it contain for the variables ("dx1" etc.) in question?

 

 

 

Bal23
Lapis Lazuli | Level 10

Thank you for explaining.

I first check proc contents on the dataset I generated

I did not see any error message. There is a format column, only one variable does have info (that is not the variables that we are talking about). All those variables that I am talking about have blank info regarding :format

 

Then I run proc contents on the dataset I have. Dx vars are char and have the length of 5. I do not know why when I use this if then, the variables I generated become numerical.

dx1 Char 5
7 dx2 Char 5
8 dx3 Char 5
9 dx4 Char 5
10 dx5 Char 5
11 dx6 Char 5
12 dx7 Char 5

FreelanceReinh
Jade | Level 19

Good to know that your dxi variables are character and their names are dx1, dx2 etc. If you code mar_head=1; SAS will indeed create a numeric variable. The value 1 is obviously numeric, so a numeric variable seems to be most appropriate. If you want character variables mar_xxxx whose possible values are only '0', '1' or missing (i.e. ' '), the assignment statements should have the form mar_head='1';

 

We haven't found out yet, why all of the mar_xxxx variables received value 0. To gain some insight into the dx1 values, please post the output of the PROC PRINT step below:

proc freq data=have order=freq noprint;
tables dx1 / out=cnt;
run;

proc print data=cnt(obs=5);
format dx1 $hex10.;
run;

 

 

 

 

 

Bal23
Lapis Lazuli | Level 10

Obs dx1 COUNT PERCENT
1 2020202020 2237 .
2 3336373220 8541 6.11084
3 3338392020 6275 4.48958
4 3336373120 5373 3.84423
5 3939352020 4622 3.30691

 

FreelanceReinh
Jade | Level 19

Great, thanks. So, the most frequent value of dx1 is '3672'. Which of the mar_xxxx variables would you have expected to get value 1 given this dx1 value?

 

Let's say, your answer would be: mar_eye. Then, what does the IF condition look like in the statement that ends with "... then mar_eye=1;"?

Bal23
Lapis Lazuli | Level 10

if substr(dx{i},1,2) in ('77')
or substr(dx{i},1,3) in('362', 'P16')
or substr(dx{i},1,4) in ('NEAR','V595')
or substr(dx{i},1,5) in ('COLOR')
or substr(dx{i},1,6) in ('EYES -', )
then do;
mar_eye=1;
end;

 

 

I am not sure what you are asking for, the above code is a similar code

FreelanceReinh
Jade | Level 19

My intention was to see if any of the relevant IF conditions is met when dx1='3672'.

 

Obviously, none of the conditions you've just posted is satisfied for dx{i}='3672'. So, if these were the real conditions, there would still be no evidence showing that any of the mar_xxxx should actually be set to 1.

Bal23
Lapis Lazuli | Level 10

I do not get that. Where did you get "3672"?

Reeza
Super User

Your condition is not being met because your code is incorrect.

 

Without a sample of data we can't really tell you how to specify it. 

 

 

FreelanceReinh
Jade | Level 19

@Bal23 wrote:

I do not get that. Where did you get "3672"?


I was able to interpret the hexadecimal ($hex10.) values that I had requested.

Bal23
Lapis Lazuli | Level 10

Would you please explain to me? Thanks. And why it is needed for trouble shooting? Thanks.

FreelanceReinh
Jade | Level 19

Hi @Bal23,

 

First of all, thank you for accepting my further inquiries as a solution. I hope you've really solved the issue.

 

The reason why I requested the PROC PRINT output in format $HEX10. was: I wanted to see what the most frequent dx1 values really are. In an output using the default character format it would be difficult to see leading blanks in a character variable. So, a value could look like '770', but in fact be ' 770' for some reason and because of the leading blank a condition such as substr(dx1,1,2)='77' would be false, contrary to expectations.

 

Moreover, character variables can contain different flavors of blank characters an even a variety of invisible characters, which are impossible to see or distinguish in a standard PROC PRINT output.

 

The $HEXw. format, however, displays all characters (under Windows) as their hexadecimal ASCII codes (requiring two hexadecimal digits per character, therefore you need $HEX10. for a character variable of length 5). For example, a standard blank is displayed as 20 (which is the hexadecimal representation of the blank's decimal ASCII code 32). Nothing can "hide" in these codes or be ambiguous, which is ideal for trouble-shooting.

 

The hex codes of the digits '0', ..., '9' happen to be 30, ..., 39. This makes them particularly easy to be read by the human eye: just read every second hex digit. So, in your example, the code 3336373220 can be easily deciphered to '3672 ' (note the trailing blank at position 5).

Bal23
Lapis Lazuli | Level 10

 I did find the problem so it is solved.
Thank you for being so patient in explaining everything to me, which makes my life so easy. I do have a lot of fun with SAS, because of your help.

FreelanceReinh
Jade | Level 19

You wrote that all of the mar_xxxx variables had value 0. So far, you have only shown code snippets which set mar_xxxx to 1 under certain conditions. What code do you use to set them to 0? When does this happen? In the same data step that contains the IF/THEN statements we've seen? If so, before those IF/THEN statements or after?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 28 replies
  • 3154 views
  • 4 likes
  • 5 in conversation