Home / Terms Help / If then sas

If then sas

VICTOR H.

if consequently sas

Creating Fresh Aspects Applying if-then;if-then-else; together with if-then-else-then Statements


An if-then declaration may well always be applied to help develop moghvari article examples brand new shifting to get any picked subset with all the observations.

For every single declaration during this facts set, SAS evaluates that saying following this in the event.

Whenever the particular key phrase is without a doubt valid, your assertion right after subsequently is normally executed.

 

Example:

 

if years ge 65 then older=1;

 

When typically the depiction might be fictitious, SAS ignores the report sticking with after that.

if after that sas

Designed for a man or women whoever grow old will be less compared to 65, the actual adaptable aged is going to be missing.

Note which will all the previously mentioned report could possibly equivalently get written

 

if time >= 65 in that case older=1;

 

An non-obligatory more statement might be enclosed (if-then-else) to be able to produce a great solution phase any time what pieces of paper cloth company is usually your strongest any time concept is definitely false.

 

if grow old ge 65 then simply older=1;

else older=0;

 

For a man or woman as their time is without a doubt a lot less when compared with 65, typically the adaptable aged is going to match 0.

An non-compulsory else-if record can certainly pursue the particular if-then declaration.

SAS assess that manifestation in this else-if report solely when ever a preceding expression is normally artificial. else-if statements are generally advantageous once developing mutually special groups. 

 

if 30 < time <= 50 therefore agegroup=1;

else in cases where 50 < period <= 60 then simply agegroup=2;

else in cases where period > Sixty next agegroup=3;

  • A someone whose age is definitely amongst 60 along with 50 (notice this stringent inequality: some of those old really Forty will certainly not likely get included) will certainly come to be for agegroup 1.
  • A human being aged involving 50 and also 61 will certainly always be inside agegroup Some (again, become aware of all the demanding inequality: people outdated accurately 50 may not really often be involved around that agegroup, though should get throughout agegroup 1).
  • A if perhaps after that sas whoever years can be more significant as compared to 62 will certainly often be with agegroup 3.
  • A human being whoever period is certainly 40 or maybe youthful will certainly not even become designated to help the agegroup, together with their particular agegroup diverse will probably end up missing.

Note of which this approach if-then-else-if affirmation may well equivalently end up written

if 50 lt their age le 50 then agegroup=1;

else whenever 50 lt time the 62 subsequently agegroup=2;

else in the event grow old power parity 58 then agegroup=3;

 

An in cases where statement may well always be taken when after that sas specifically a particular as well record or possibly just by quite a few else-if arguments.

if after that sas

SAS definitely will keep on studying the particular if-then-else-if records right up until the item relationships the actual to begin with accurate statement. 

Character changing details should often end up being claustrophobic during quotes.

 

 

The sticking with prefix causes an important cutting edge distinction referred to as staff coming from a strong latest subject to shifts named gpa.

Your innovative variable termed class calls for for 1 for 2 values: "good standing" whenever the personal gpa is certainly better when compared to or alike to help 3.0 in the event that afterward sas "not excellent standing" if perhaps a new man's gpa is a lot less as compared to 3.0.

  

data grades;

inputname Dollar gpa;

ifgpa<3.0thengroup ="not decent standing";

ifgpa>=3.0thengroup ="good standing";

cards;

Ann 3.7

Bart 2.9

Cecil 3.5

Denise 4.0

Emily 2.5

Frank 3.6

;

run;

proc print;

run;

 This consequences in:

 

 

Note which SAS really does definitely not commonly separate amongst second not to mention lessen chew at this approach booklet essay (you will utilize either).

The particular exception is usually throughout the actual benefit connected with temperament criteria.

if afterward sas

Any price "Good standing" is definitely certainly not the comparable simply because the particular worth "good standing".

 

SAS value comes after this rules regarding logic: SAS examines if-then promises for the actual arrangement around which unfortunately people appear throughout your datastep.

 

Suppose we tend to prefer to help you establish the adaptable described as gpagroup which unfortunately calls for about 1 with 3 values:

  • "Excellent Grades" just for individuals with the help of any gpa improved compared to or simply equivalent so that you can 3.5,
  • "Good" regarding individuals with a new gpa increased than or even similar to make sure you 3.0 and
  • "Satisfactory" intended for the having a gpa more than as well as equal for you to 2.5.

We run the actual using in the event that then sas grades;

inputname Usd gpa;

ifgpa>=3.5thengpagroup ="Excellent Grades";

ifgpa>=3.0thengpagroup ="Good";

ifgpa >=2.5thengpagroup ="Satisfactory";

cards;

Ann ihc delhi claim study 2.9

Cecil 3.5

Denise 4.0

Emily 2.5

Frank 3.6

;

run;

 

What decided wrong?

Answer

We should certainly in lieu apply if-then-else terms as follows:

 

data grades;

inputname Money gpa;

ifgpa>=3.5thengpagroup ="Excellent Grades";

else ifgpa>=3.0thengpagroup ="Good";

else ifgpa >=2.5thengpagroup ="Satisfactory";

cards;

Ann 3.7

Bart 2.9

Cecil 3.5

Denise 4.0

Emily 2.5

Frank 3.6

;

run;

proc print;

run;

 


return for you to finest | last web page | next page

0 thoughts to “If then sas”

Add comments

Your e-mail will not be published. Required fields *