BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PriyaB
Fluorite | Level 6
data out;
	set INPUT.input44;
	drop bp_status weight_status smoking_status;

	if cholesterol lt 200 then
		do;
			chol="SAFE";
			output safe;
		end;
	Else if cholesterol le 239 then
		do;
			chol="HIGH_BORDRLINE";
			output high_bord;
		end;
	else if cholesterol ge 240 then
		do;
			chol="HIGH";
			output high;
		end;
	where cholesterol is not missing;
RUN;

Log Section:

PriyaB_0-1713838346474.png

 

please let me know in simple way where i am lacking as I am new to SAS and learning it .

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

If you use an OUTPUT statement with a data set name to write to then you need this output data set also in your DATA statement.

data SAFE HIGH_BORD HIGH;
  .....
      output safe;
  .....
      output high_bord;
  .....
      output high;
  .....
run;

Looking at your code I feel that it might be better to just populate a variable and write all the data to a single table.

data out;
  set INPUT.input44;
  drop bp_status weight_status smoking_status;

  length chol $14;
  if cholesterol lt 200 then
    do;
      chol="SAFE";
    end;
  else if cholesterol le 239 then
    do;
      chol="HIGH_BORDRLINE";
    end;
  else if cholesterol ge 240 then
    do;
      chol="HIGH";
    end;

  where cholesterol is not missing;
RUN;

One neat and easy to maintain option for recoding values is the use of a format.

proc format;
  value chol_group
    low-<200 = 'SAFE'
    200-<240 = 'HIGH_BORDRLINE'
    240-high = 'HIGH'
    other    = 'not defined'
    ;
run;

data out;
  set INPUT.input44;
  where cholesterol is not missing;
  drop bp_status weight_status smoking_status;
  chol=put(cholesterol,chol_group.);
RUN;

 

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You cannot output to a dataset that you did not tell SAS the data step was going to create.  If you want to write to three different datasets then you must list all of them in the DATA statement, just as the message says.

 

Also do not put the WHERE statement so far away from the SET statement that it applies to.  You will just confuse yourself.

data safe high_bord high;
  set INPUT.input44;
  where cholesterol is not missing;

 

PriyaB
Fluorite | Level 6
Thank you Tom 🙂
Patrick
Opal | Level 21

If you use an OUTPUT statement with a data set name to write to then you need this output data set also in your DATA statement.

data SAFE HIGH_BORD HIGH;
  .....
      output safe;
  .....
      output high_bord;
  .....
      output high;
  .....
run;

Looking at your code I feel that it might be better to just populate a variable and write all the data to a single table.

data out;
  set INPUT.input44;
  drop bp_status weight_status smoking_status;

  length chol $14;
  if cholesterol lt 200 then
    do;
      chol="SAFE";
    end;
  else if cholesterol le 239 then
    do;
      chol="HIGH_BORDRLINE";
    end;
  else if cholesterol ge 240 then
    do;
      chol="HIGH";
    end;

  where cholesterol is not missing;
RUN;

One neat and easy to maintain option for recoding values is the use of a format.

proc format;
  value chol_group
    low-<200 = 'SAFE'
    200-<240 = 'HIGH_BORDRLINE'
    240-high = 'HIGH'
    other    = 'not defined'
    ;
run;

data out;
  set INPUT.input44;
  where cholesterol is not missing;
  drop bp_status weight_status smoking_status;
  chol=put(cholesterol,chol_group.);
RUN;

 

 

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
  • 3 replies
  • 232 views
  • 2 likes
  • 3 in conversation