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
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
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_;
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.
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_=;
put _all_ will include writing _n_. If you want _n_ only, you could try:
put _n_=;
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.
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.
You seem to be missing a END for your second DO.
Looks like it is working to me.
1565 is NOT less than 1565. So the ELSE clause should execute.
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".
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.