I supposed the answer to be Buenos Aires.
But I get Buenos Aires, Argentina as correct ans.
Plz explain how the this works.
Please always share code as text and not as screenshot.
%let location=%str(Buenos Aires, Argentina);
%let city=%scan(&location, 1, %str(,));
%put &=city;
The documentation tells you that %scan() allows for FOUR parameters.
The last comma in your code is not interpreted as the delimiter for the charlist but as separator for the next parameter modifier. This means that you define the value for charlist blank meaning there isn't any.
To get what you want quote the last comma so it gets used as value for charlist.
%let location=%str(Buenos Aires, Argentina);
%let city=%scan(&location, 1, %str(,));
%put &=city;
Please always share code as text and not as screenshot.
%let location=%str(Buenos Aires, Argentina);
%let city=%scan(&location, 1, %str(,));
%put &=city;
The documentation tells you that %scan() allows for FOUR parameters.
The last comma in your code is not interpreted as the delimiter for the charlist but as separator for the next parameter modifier. This means that you define the value for charlist blank meaning there isn't any.
To get what you want quote the last comma so it gets used as value for charlist.
%let location=%str(Buenos Aires, Argentina);
%let city=%scan(&location, 1, %str(,));
%put &=city;
If you don't specify explicit characters as delimiters then the default list will get used. This applies both for scan() and %scan() and is fully documented.
But you did include it.
Just try it without the extra commas to get the default delimiters.
1 %let location=%str(Buenos Aires, Argentina); 2 %put city=%scan(&location, 1, %str(,)); city=Buenos Aires 3 %put city=%scan(&location, 1); city=Buenos 4 %put city=%scan(&location, 1,); city=Buenos Aires, Argentina 5 %put city=%scan(&location, 1,,); city=Buenos Aires, Argentina
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.