BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

When I run the following code, I got 'not success' in the log where as I'm execpting 'sucess' message in the log. Can someone explain this code?

 

%let end_title=1565;
%macro test;
data test1;
if %eval(&end_title)<1565< %eval(&end_title)+%eval(&end_title) then put 'success';
else put "notsucess";
_n=%eval(&end_title)+%eval(&end_title);
run;
%mend test;
%test
12 REPLIES 12
Astounding
PROC Star

That's a question that pops up from time to time .,.. here's oen thread you can look at:

 

https://communities.sas.com/t5/Base-SAS-Programming/Macro-resolving/m-p/218619#M40282

 

 

Babloo
Rhodochrosite | Level 12

Could you please tell me how to print the value of _n_  in log from the following code? I could not see the value of _n_ after placing the put _all_ statement.

 

 

if 1<_n_< %eval(&end_title) then do; put option;end;
put _all_;
if _n_=%eval(&end_title) then do; put option;		
put _all_;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Lets start again.  What are you attempting to do.  There is nothing there (again) which needs macro code.  There is then the difference in the code you posted, in the first instance you use _n which is a variable or macro variable?  in the latest post you use _n_ wihch is an automatic variable for row number.  What is the purpose, the logic, i.e. what goes in (as a datastep) and what do you want the output to look like.

Babloo
Rhodochrosite | Level 12

My first and second post is not related to each other. I missed to start a new thread for my second post. I need to get the value the _n_ in SAS log. When I tried this code, I'm not getting the value of _n_ in SAS log.

 

if 1<_n_< %eval(&end_title) then do; put option;end;
put _all_;
if _n_=%eval(&end_title) then do; put option;		
put _all_;

I tried this code as well, but could not suceeed. 

if 1<_n_< %eval(&end_title) then do; put option;end;
put _n_=;
if _n_=%eval(&end_title) then do; put option;		
put _n_=;
Astounding
PROC Star

put _all_ will include writing _n_.  If you want _n_ only, you could try:

 

put _n_=;

Babloo
Rhodochrosite | Level 12
I did tried as I said my previous, but I could not see the value of _n_ in SAS log.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, you still have not explained what you are trying to do, what is the input data, what is the output requirement.  The reason is in base SAS, this works fine:

data tmp;
set sashelp.cars;
put _n_;
run;

 

It prints the row number for each record in the dataset.  I can't see what your trying to do.

Babloo
Rhodochrosite | Level 12

I'm not getting the value of _n_ after I place the end statement. I should have get the value of _n_ for the first do lopp atleast, but not.

Tom
Super User Tom
Super User

You seem to be missing a END for your second DO.

Tom
Super User Tom
Super User

Looks like it is working to me.

1565 is NOT less than 1565.  So the ELSE clause should execute.

arodriguez
Lapis Lazuli | Level 10
After macro replacement your if clause is

if 1565<1565<1565+1565 then put 'success';
else put "notsucess";

1565 is not les than 1565 so the else clause is executed and print "notsucess" message
PGStats
Opal | Level 21

Logic:

1565 < 1565 < 1565+1565 is equivalent to 

1565 < 1565 < 3130 is equivalent to

1565 < 1565 and 1565 < 3130

since 1565 is not < 1565, the result is FALSE

hence "not success".

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

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

 

Register now!

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
  • 12 replies
  • 1357 views
  • 4 likes
  • 6 in conversation