data ds;
set sashelp.cars;
if Make='volkswagan' then call symput("Status",'Available');
else call symput("Status",'Not Avaialable');
run;
%put &Status.;
it shows wrong output
Check the variable "Make" - i am 100% sure that it never has the value "volkswagan".
@BrahmanandaRao wrote:
IF NOT AVAILABLE IT SHOULD BE SHOWS IN NOT AVAILABLE IN LOG WINDOW AS PER THE IF ELSE CONDITION
If you're using SAS EG or DMS, read the doc on the data step debugger.
Read the log (Maxim 2) and the documentation (Maxim 1) of IF, and you will qickly find out what is missing.
Hi @BrahmanandaRao ,
Are you sure the code you have posted to this forum is the code you are using?
When I try submitting the posted code I get a syntax error indicating what is wrong with the code.
Please copy the code you have posted and run it in SAS to see if you get anything different to what you were running yourself, then, if necessary, edit the original question to show the code you are running.
If you are not receiving any error message then please post your log showing the code and log messages using the "insert code" icon.
Kind regards,
Amir.
Hello,
Note that instructions in a data step are executed for each iteration of the data step.
Since the macrovariable name you declare in the call symputs are not observation dependant,
&status. will be overwritten at each iteration and will eventually be equal to the value
for the last observation of the dataset. If you really want the value for the last observation,
you don't need to read the whole dataset. See for instance :
Alternatively, if you want to create one macrovariable per observation, youcan suffix their
names with the observation number :
call symputx(cats('statut_',_N_), Make);
Note that i used symputx instead of symput as it strips the string in argument before exporting it
into a macrovariable, which is generally what is wanted.
In your test, since you are comparing strings, you can upcase them to avoid rejection
because of case differences :
if upcase(Make)='VOLKSWAGEN' ...
Edit : A last advice is to carefully check the spelling, which i should have done before writing 'WOLKSWAGEN' 😀
@BrahmanandaRao wrote:
data ds; set sashelp.cars; if Make='volkswagan' then call symput("Status",'Available'); else call symput("Status",'Not Avaialable'); run; %put &Status.;
it shows wrong output
WHAT OUTPUT ARE YOU EXPECTING?
Now that you have added the necessary THEN, the step will run, but only the result of the last observation will end up in the macro variable. Since you also have quite incorrect spelling of the compare string, this will always be
Not Avaialable
@BrahmanandaRao wrote:
data ds; set sashelp.cars; if Make='volkswagan' then call symput("Status",'Available'); else call symput("Status",'Not Avaialable'); run; %put &Status.;
it shows wrong output
And just what should be the right output???
I get "Not Avaialable" (your spelling not mine) with the above code.
Since this leaves the STATUS as of the very last record in the input data set are you sure that is what you wanted?
The last make in the data set is Volvo so even without the incorrect spelling of "volkswagen" you will never get 'Available' as a result.
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.