BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

How could I change this to work wiht the and?

if V > 1then C ='Door' and D='Window";

else if V < 1 then C='Door2' and D2 = 'Window2".

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

if v>1 then do;

     c='Door';

     d='window';

   end;

else do;

     c='Door2';

     d='window2';

  end;

podarum
Quartz | Level 8

What if I have something like this :

if V > 1then C ='Door' and D='Window";

else if V > 2 then C='Door2' and D2 = 'Window2"

else if V > 3 then C='Door3' and D= 'Window3':

Tom
Super User Tom
Super User

AND is usually restricted to the logical operator in programming languages.

You are using AND in the sense of THIS AND ALSO THE OTHER.  In programming languages you usually use some type of grouping syntax to say that two or more things should go together.  In SAS you would use DO; ... END; statements to do this grouping.  (Also match sure to match your quotes properly)

if V > 1 then do; C ='Door' ;  D='Window'; end;

else if V > 2 then do; C='Door2'; D2 = 'Window2'; end;

else if V > 3 then do; C='Door3';  D= 'Window3'; end;

Linlin
Lapis Lazuli | Level 10

Hi Tom,

I think your code should be:

data have;

input v @@;

cards;

1 2 3 4 5 6

;

data want;

  set have;

if V > 3 then do; C='Door3';  D= 'Window3'; end;

else if V > 2 then do; C='Door2'; D = 'Window2'; end;

else if V > 1 then do; C ='Door' ;  D='Window'; end;

run;

proc print;run;

                           Obs    v      C         D

                             1     1

                            2     2    Door     Window

                            3     3    Door2    Window2

                            4     4    Door3    Window3

                            5     5    Door3    Window3

                            6     6    Door3    Window3

Thank you!

Linlin

Tom
Super User Tom
Super User

Thanks. I just copied the code from above and put in DO; END; statements.

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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