ok I found the solution.see below. in the scan I forgot to specify the separator space. this code below works as I intended
%macro mc_boucle_surlesjours ;
%local i next_jour;
%let i=1;
%do %while (%scan(&liste_jour, &i, " ") ne );
%let next_jour = %scan(&liste_jour, &i, " ");
%put -->&next_jour ;
%let i = %eval(&i + 1);
%end ;
%mend ;
Please re-format your problem description to make it readable. Thanks.
Repeating:
Please re-format your problem description to make it readable.
ok I found the solution.see below. in the scan I forgot to specify the separator space. this code below works as I intended
%macro mc_boucle_surlesjours ;
%local i next_jour;
%let i=1;
%do %while (%scan(&liste_jour, &i, " ") ne );
%let next_jour = %scan(&liste_jour, &i, " ");
%put -->&next_jour ;
%let i = %eval(&i + 1);
%end ;
%mend ;
@Nasser_DRMCP wrote:
by executing this %macro mc_boucle_surlesjours ; %local i next_jour; %let i=1; %do %while (%scan(&liste_jour, &i) ne ); %let next_jour = %scan(&liste_jour, &i); %put -->&next_jour ; %let i = %eval(&i + 1); %end ; %mend ; %mc_boucle_surlesjours ; the result is -->01 -->01 -->2022 -->02 -->01 -->2022 -->03 -->01 -->2022 -->04 -->01 -->2022 -->05 -->01 -->2022 -->06 -->01 -->2022 -->07 ...
Do not post code as plain unformatted text. Post code in the box that appears when you click on the "Insert SAS Code" icon. You may have found the correct answer, but again, I ask you to re-format it to be readable by using the "Insert SAS Code" icon, for the benefit of everyone else.
Read your post and then look at this:
data have; input jour DDMMYY10. ; format jour DDMMYY10. ; datalines; 01/01/2022 02/01/2022 03/01/2022 04/01/2022 05/01/2022 06/01/2022 07/01/2022 08/01/2022 09/01/2022 10/01/2022 11/01/2022 ; proc sql noprint; select distinct jour into :liste_jour separated by ' ' from have ; quit ; %put &liste_jour; %macro mc_boucle_surlesjours ; %local i next_jour; %do i = 1 %to %sysfunc(countw(&liste_jour,%str( ))); %let next_jour = %scan(&liste_jour, &i,%str( )); %put -->&next_jour ; %end ; %mend ; %mc_boucle_surlesjours ;
That is part of what is meant by "reformat your post".
The above does part of what I think you want.
Problem: using SCAN by default will treat the / character as delimiter between words. The fix above forces a space into the parameters for Countw and Scan functions as the only delimiter.
Or depending on how you expect to use those dates do not apply a format. Really the only time a macro Date value should be formatted is when it is read my humans such as in a title, footnote or possibly a file name.
If you do not format the date variable you will get the numbers that represent the date and can be used if comparisons or other date related functions and would not need the forced space from the %Str
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: