If statement

Reply
Contributor
Posts: 30

If statement

Hi!

I need to have a result in case the macro es "No" or is "Si".

The &Dato and &Dato1 come from a prompt in the program.

I tried the following and is not working.

if &Dato="No" then do;

  _cashflow_.ST_003.matamt=sum( RF_003_1_Rel)/dolar;

  _cashflow_.ST_004.matamt=sum( RF_004_1_Rel)/dolar;

  _cashflow_.ST_005.matamt=sum( RF_005_1_Rel)/dolar;

  _cashflow_.ST_006.matamt=sum( RF_006_1_Rel)/dolar;

  _cashflow_.ST_007.matamt=sum( RF_007_1_Rel)/dolar;

  _cashflow_.ST_008.matamt=sum( RF_008_1_Rel)/dolar;

  end;

  if &Dato1="Si" then do;

  _cashflow_.ST_003.matamt=sum(ST_003_H, RF_003_1_Rel)/dolar;

  _cashflow_.ST_004.matamt=sum(ST_004_H, RF_004_1_Rel)/dolar;

  _cashflow_.ST_005.matamt=sum(ST_005_H, RF_005_1_Rel)/dolar;

  _cashflow_.ST_006.matamt=sum(ST_006_H, RF_006_1_Rel)/dolar;

  _cashflow_.ST_007.matamt=sum(ST_007_H, RF_007_1_Rel)/dolar;

  _cashflow_.ST_008.matamt=sum(ST_008_H, RF_008_1_Rel)/dolar;

  end;

Hope you can help me with this.

Thanks and kind regards,

Maria

Respected Advisor
Posts: 3,124

Re: If statement

Not working how? did it error out or did it not get what you expected? You mention prompts, is it part of stored process? Please share more details, such as logs, some background to help us to you.

Contributor
Posts: 30

Re: If statement

Thank you.

I run a macro (with the prompt) and I need to get a value in case the macro is "No" and another value in case it "Si". I do not get an error when runnning the script I put. Put the results are not the expected ones.

In the log it says that the macro is get the correct value but when I go to the results they are the same in both cases.

I hope you can help me with this.

Contributor
Posts: 30

Re: If statement

I put "No" and I get the results of "Si".

Respected Advisor
Posts: 3,124

Re: If statement

We probably need more specifics. Have you tried to investigate by turning on those macro options: options symbolgen mprint mlogic; ? It sounds to me your problem maybe macro variable "scope" related. how does your code define the scope by using %local or %global?

Contributor
Posts: 30

Re: If statement

If I put %let data="No" or %let data="Si", it works.

But I need to get the macro from the prompt.

Super User
Posts: 3,102

Re: If statement

Try this - if "&Dato"="No" then do; - if you don't want &Dato to have quotes to start with

PROC Star
Posts: 7,363

Re: If statement

: a couple of things. First, it may not be working because of how &data was defined. Try the following:

\

%let Dato=No;

data test;

  if &Dato="No" then test=1;

  else if &Dato=No then test=2;

run;

Second, your use of sum in the first if is irrelevant as you aren't summing anything.

Message was edited by: Arthur Tabachneck

Contributor
Posts: 30

Re: If statement

Thank you.

I tried and I the following error;

if &Dato="No" then;

1857       _cashflow_.ST_003.matamt=sum(RF_003_1_Rel);

1858       _cashflow_.ST_004.matamt=sum(RF_004_1_Rel);

1859       _cashflow_.ST_005.matamt=sum(RF_005_1_Rel);

ERROR: The ELSE statement does not have a matching IF statement at línea 1864 columna 5.

SYMBOLGEN:  La macro variable DATO se resuelve en No

1860       _cashflow_.ST_006.matamt=sum(RF_006_1_Rel);

1861       _cashflow_.ST_007.matamt=sum(RF_007_1_Rel);

1862       _cashflow_.ST_008.matamt=sum(RF_008_1_Rel);

1863     

1864       else if &Dato="Si" then;

1865       _cashflow_.ST_003.matamt=sum(ST_003_H ,RF_003_1_Rel);

1866       _cashflow_.ST_004.matamt=sum(ST_004_H ,RF_004_1_Rel);

1867       _cashflow_.ST_005.matamt=sum(ST_005_H ,RF_005_1_Rel)*10000;

1868       _cashflow_.ST_006.matamt=sum(ST_006_H ,RF_006_1_Rel);

1869       _cashflow_.ST_007.matamt=sum(ST_007_H ,RF_007_1_Rel);

1870       _cashflow_.ST_008.matamt=sum(ST_008_H ,RF_008_1_Rel);

1871       end;

1872      

PROC Star
Posts: 7,363

Re: If statement

You are missing an end statement after the last of your first if statement.

Contributor
Posts: 30

Re: If statement

I tried with the following;

data g;

set g;

  if &Dato="No" and prueba="3-1" then Saldo=0;

  if &Dato="No" and prueba="4-1" then Saldo=0;

  if &Dato="No" and prueba="5-1" then Saldo=0;

  if &Dato="No" and prueba="6-1" then Saldo=0;

  if &Dato="No" and prueba="7-1" then Saldo=0;

  if &Dato="No" and prueba="8-1" then Saldo=0;

run;

And the warning is:

29        

30         data g;

31         set g;

32       

SYMBOLGEN:  La macro variable DATO se resuelve en No

32       !  if &Dato="No" and prueba="3-1" then Saldo=0;

33       

SYMBOLGEN:  La macro variable DATO se resuelve en No

33       !  if &Dato="No" and prueba="4-1" then Saldo=0;

34       

2                                                           Sistema SAS                             15:40 Tuesday, February 10, 2015

SYMBOLGEN:  La macro variable DATO se resuelve en No

34       !  if &Dato="No" and prueba="5-1" then Saldo=0;

35       

SYMBOLGEN:  La macro variable DATO se resuelve en No

35       !  if &Dato="No" and prueba="6-1" then Saldo=0;

36       

SYMBOLGEN:  La macro variable DATO se resuelve en No

36       !  if &Dato="No" and prueba="7-1" then Saldo=0;

37       

SYMBOLGEN:  La macro variable DATO se resuelve en No

37       !  if &Dato="No" and prueba="8-1" then Saldo=0;

38         run;

Do you know why is this happening?

NOTE: Variable No is uninitialized.

NOTE: There were 2147 observations read from the data set WORK.G.

Super User
Posts: 17,808

Re: If statement

Try the following, noting that your current step replaces your G data set. You may need to re-create it before it works properly.

data g;

set g;

  if "&Dato"="No" and prueba in ("3-1", "4-1", "5-1", "6-1", "7-1", "8-1") then Saldo=0;

run;

Ask a Question
Discussion stats
  • 11 replies
  • 270 views
  • 0 likes
  • 5 in conversation