BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

 

data ds;
set sashelp.class ;
if age=11 then do;
   ages1='Minor';
   else if age= ' ' then ages1='--';
   end;
if age>11 then do;
ages2='Major';
else if age=' ' then ages2='--';
end;

proc print noobs;
run;   

Required Output:

Name Sex Age Height Weight ages1 ages2
Alfred M 14 69 112.5 -- Major
Alice F 13 56.5 84 -- Major
Barbara F 13 65.3 98 -- Major
Carol F 14 62.8 102.5 -- Major
Henry M 14 63.5 102.5 -- Major
James M 12 57.3 83 -- Major
Jane F 12 59.8 84.5 -- Major
Janet F 15 62.5 112.5 -- Major
Jeffrey M 13 62.5 84 -- Major
John M 12 59 99.5 -- Major
Joyce F 11 51.3 50.5 Minor --
Judy F 14 64.3 90 -- Major
Louise F 12 56.3 77 -- Major
Mary F 15 66.5 112 -- Major
Philip M 16 72 150 -- Major
Robert M 12 64.8 128 -- Major
Ronald M 15 67 133 -- Major
Thomas M 11 57.5 85 Minor --
William M 15 66.5 112 -- Major

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Is there a question you want to ask?

Do you want us to guess what the question might be?

 

Why do you treat AGE as NUMERIC in the first place you mention it.  But then treat it as CHARACTER the second place you mention it?

 

Which type of variable is AGE?  Numeric or character?

 

And why would you test AGE a second time within the DO/END block that can only be entered when AGE is 11 ?  You already know that the value of AGE is 11 or it would never have gotten to that second test.

 

It looks like you only need to test age ONCE since you only have two different outputs.

 

data want;
  set sashelp.class;
  length ages1 ages2 $5 ;
  if age = 11 then do;
    ages1='Minor';
    ages2='--';
  end;
  else do;
    ages2='Major';
    ages1='--';
  end;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Is there a question you want to ask?

Do you want us to guess what the question might be?

 

Why do you treat AGE as NUMERIC in the first place you mention it.  But then treat it as CHARACTER the second place you mention it?

 

Which type of variable is AGE?  Numeric or character?

 

And why would you test AGE a second time within the DO/END block that can only be entered when AGE is 11 ?  You already know that the value of AGE is 11 or it would never have gotten to that second test.

 

It looks like you only need to test age ONCE since you only have two different outputs.

 

data want;
  set sashelp.class;
  length ages1 ages2 $5 ;
  if age = 11 then do;
    ages1='Minor';
    ages2='--';
  end;
  else do;
    ages2='Major';
    ages1='--';
  end;
run;
Srinivas_Naren
Calcite | Level 5

Instead of creating two variables we can perform with one 


data edit;
set sashelp.class;
if age >= 15 then do;
applied='Major';
end;
else if age<15 then do;
applied='Minor';
end;
run;
proc print data = edit;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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