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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1121 views
  • 2 likes
  • 3 in conversation