Desktop productivity for business analysts and programmers

regarding if and statement use

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

regarding if and statement use

How many times I can use and condition when I like to tag something.

for example:-

these are datasets follows:-

data lowl_high;
input loanid $ Gender$ Married$ Depender Education$ Self_employed$ Applicantincome Coapplicantincome Loanamount Loan_amount_term Credit_history Propertyarea$ ;
datalines;
LP001011 male Yes 0 Graduate No 5720 0 110 360 1 Urban
LP001012 female Yes 1 Graduate No 5730 0 112 372 2 SemiUrban
LP001013 female No 2 NonGraduate Yes 5740 1 114 380 3 Urban
LP001014 male No 0 Graduate No 5750 1 115 390 2 Semiurban
LP001015 female Yes 1 NonGraduate Yes 5760 0 116 400 1 Semiurban
LP001016 male No 0 Graduate Yes 5770 2 117 410 0 Urban
LP001017 female Yes 1 Graduate No 5780 1 118 420 1 Semiurban

 

but I am facing problem regarding this query:-

data Important9;
set Lowl_high;
Length Tag $15;
if Gender="female" and Married="Yes" and Education="Graduate" then Tag="High";
Else Tag="Low";
Run;

kindly help


Accepted Solutions
Solution
‎04-14-2018 06:56 PM
PROC Star
Posts: 1,336

Re: regarding if and statement use

Posted in reply to sumansparsh

I ran your code. It seems to work fine. Below is the log:

 

3178 data lowl_high;
3179 input loanid $ Gender$ Married$ Depender Education$ Self_employed$
3179! Applicantincome Coapplicantincome Loanamount Loan_amount_term
3179! Credit_history Propertyarea$ ;
3180 datalines;

NOTE: The data set WORK.LOWL_HIGH has 7 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


3188 ;
3189 data Important9;
3190 set Lowl_high;
3191 Length Tag $15;
3192 if Gender="female" and Married="Yes" and Education="Graduate" then
3192! Tag="High";
3193 Else Tag="Low";
3194 Run;

NOTE: There were 7 observations read from the data set WORK.LOWL_HIGH.
NOTE: The data set WORK.IMPORTANT9 has 7 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

Results:/*is this your expected result?*/

loanidGenderMarriedDependerEducationSelf_employedApplicantincomeCoapplicantincomeLoanamountLoan_amount_termCredit_historyPropertyareaTag
LP001011maleYes0GraduateNo572001103601UrbanLow
LP001012femaleYes1GraduateNo573001123722SemiUrbaHigh
LP001013femaleNo2NonGraduYes574011143803UrbanLow
LP001014maleNo0GraduateNo575011153902SemiurbaLow
LP001015femaleYes1NonGraduYes576001164001SemiurbaLow
LP001016maleNo0GraduateYes577021174100UrbanLow
LP001017femaleYes1GraduateNo578011184201SemiurbaHigh

View solution in original post


All Replies
PROC Star
Posts: 1,336

Re: regarding if and statement use

Posted in reply to sumansparsh

what is the problem? Please help understand the problem

New Contributor
Posts: 3

Re: regarding if and statement use

Posted in reply to novinosrin
data Important9;
set Lowl_high;
Length Tag $15;
if Gender="female" and Married="Yes" and Education="Graduate" then Tag="High";
Else Tag="Low";
Run;
I can not get the result after run this syntax
actually I want to get result by three condition by using add,but I failed to do so
Solution
‎04-14-2018 06:56 PM
PROC Star
Posts: 1,336

Re: regarding if and statement use

Posted in reply to sumansparsh

I ran your code. It seems to work fine. Below is the log:

 

3178 data lowl_high;
3179 input loanid $ Gender$ Married$ Depender Education$ Self_employed$
3179! Applicantincome Coapplicantincome Loanamount Loan_amount_term
3179! Credit_history Propertyarea$ ;
3180 datalines;

NOTE: The data set WORK.LOWL_HIGH has 7 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


3188 ;
3189 data Important9;
3190 set Lowl_high;
3191 Length Tag $15;
3192 if Gender="female" and Married="Yes" and Education="Graduate" then
3192! Tag="High";
3193 Else Tag="Low";
3194 Run;

NOTE: There were 7 observations read from the data set WORK.LOWL_HIGH.
NOTE: The data set WORK.IMPORTANT9 has 7 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

Results:/*is this your expected result?*/

loanidGenderMarriedDependerEducationSelf_employedApplicantincomeCoapplicantincomeLoanamountLoan_amount_termCredit_historyPropertyareaTag
LP001011maleYes0GraduateNo572001103601UrbanLow
LP001012femaleYes1GraduateNo573001123722SemiUrbaHigh
LP001013femaleNo2NonGraduYes574011143803UrbanLow
LP001014maleNo0GraduateNo575011153902SemiurbaLow
LP001015femaleYes1NonGraduYes576001164001SemiurbaLow
LP001016maleNo0GraduateYes577021174100UrbanLow
LP001017femaleYes1GraduateNo578011184201SemiurbaHigh
New Contributor
Posts: 3

Re: regarding if and statement use

Posted in reply to sumansparsh
Thank you so much
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 147 views
  • 0 likes
  • 2 in conversation