BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I would like to make the change in the code shown below.   'uairway' and 'ulungoth' are numeric; while 'uairwayothsp', 'Ulungothsp', and 'record_updated' are the character. 

data want (keep=ulungoth Ulungothsp record_updated uairway uairwayothsp);
	set have;

	if caseid in ('EUJK009') then Ulungothsp='CHRONIC RESPIRATORY FAILURE, BIPAP DEPENDENT' and ulungoth=1 
									and record_updated='Yes' and uairway=0 and uairwayothsp=' ';

	if caseid in ('EUJK009');
run;

The log window showed the massage below:

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
236:48
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
237:76
NOTE: Invalid numeric data, 'CHRONIC RESPIRATORY FAILURE, BIPAP DEPENDENT' , at line 236 column 48.

 

Then, I didn't see any change in the result I want in the (ulungoth Ulungothsp record_updated uairway uairwayothsp) columns.   Where did I do wrong and how to fix it?  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Unless you want a dataset of identical rows... I guess you may want something like this:

 

data want (keep=ulungoth Ulungothsp record_updated uairway uairwayothsp);
	set have;

	if caseid in ('EUJK009') then do;
		Ulungothsp='CHRONIC RESPIRATORY FAILURE, BIPAP DEPENDENT';
		ulungoth=1;
		record_updated='Yes';
		uairway=0;
		uairwayothsp=' ';
		end;
run;

i.e. to execute many statements when a condition is true, you need a DO END group.

PG

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Please show us the entire log for this data step, including the code as it appears in the log, as well as all NOTEs, WARNINGs and ERRORs. 

 

From now on, please do not show us errors detached from the code that caused the error.

--
Paige Miller
PGStats
Opal | Level 21

Unless you want a dataset of identical rows... I guess you may want something like this:

 

data want (keep=ulungoth Ulungothsp record_updated uairway uairwayothsp);
	set have;

	if caseid in ('EUJK009') then do;
		Ulungothsp='CHRONIC RESPIRATORY FAILURE, BIPAP DEPENDENT';
		ulungoth=1;
		record_updated='Yes';
		uairway=0;
		uairwayothsp=' ';
		end;
run;

i.e. to execute many statements when a condition is true, you need a DO END group.

PG
ybz12003
Rhodochrosite | Level 12
Awesome, thanks much!
Kurt_Bremser
Super User

This expression:

'CHRONIC RESPIRATORY FAILURE, BIPAP DEPENDENT' and ulungoth=1 
and record_updated='Yes' and uairway=0 and uairwayothsp=' '

is a logical expression which will be true if ulungoth = 1, record_updated = "Yes", uairway = 0 and uairwayothsp is missing (empty string). The first part (a non-missing string) is always considered "true".

The result of a logical expression is numeric and either 0 (false) or 1 (true). If the variable on the left side of the assignment is not already defined, the data step compiler will implicitly define it as numeric.

 

MisterJenn
Fluorite | Level 6

I keep getting an error message every time I run the code. I went over it with my TA and assumed everything was correct but I keep getting error message. 

This is the error message I get; ERROR 180-322: Statement is not valid or it is used out of proper order.

Please help the assignment is due tomorrow!!

 

* I am trying to answer question 1

 

This is what is in the editor window: 

libname hw3 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Week 3';
data fit1temp;
set hw3.fit2;if upcase(compress(smoke)) = "CURRENTSMOKER" then currentsmoker = 1;
else if upcase(compress(smoke)) = "NONSMOKER" or
upcase(compress(smoke)) = "FORMERSMOKER" then currentsmoker = 0
proc freq data=hw3.fit2;
table blvfx blnspfx;
if blvfx = "yes" or blnspfx = "yes" then any_base_frac = 1;
else if blvfx = "no" and blnspfx = "no" then = any_base_frac = 0;
if newvfx = "yes" and newnspfx = "yes" then any_new_frac = 1;
else if newvfx = "no" and newnspfx = "no" then any_new_frac = 0;
if bmi > 25 then bmi2 = "overweight";
else if 0 < bmi <= 25 then bmi2 = "normal";
if 0 < bmi <= 18 then bmi3 = "underweight";
else if 18 < bmi <= 25 then bmi3 = "normal";
else if bmi > 25 then bmi3 = "overweight";

bmi1_ind = (bmi > 25);
bmi2_ind = (18 < bmi <= 25);
bmi3_ind = (0 < bmi <= 18);
i_tx = (tx = "Alendronate");
diff_bmd = cobmd-blbmd;
age = (dov - dob)/365.25;
run;

ybz12003
Rhodochrosite | Level 12

Create a new post for your question.  Ask the community experts to help you, in additions, insert your code in the SAS code format.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1128 views
  • 3 likes
  • 5 in conversation