07-28-2015 02:11 PM
I plan to use file names as macro arguments. The file names start with different numbers of characters and end with mmddyyyy.csv . To extract the mm (month), dd (day of month), and yyyy (year), I would like to use the %scan function (as opposed to the more complicated code needed to run prx functions in macros).
%let myStr = fileNameXy_blah_blah07282015.csv,
can someone please tell me if I can use %scan to get 07282015 from &myStr?
07-28-2015 02:45 PM
so I would use %length to determine how many characters &myStr has and then figure out how far from the end I'd need to start as my first position in %substr. I'll give it a try. Thanks for the suggestion.
07-28-2015 03:06 PM
Will it always be CSV?
Keep in mind the reverse() function. A double reverse and substr would work if you always know that you'll have that structure.
reverse(substr(reverse(string), 4, 8));
07-28-2015 03:04 PM
Explore using macro language %SYSFUNC(...) along with SCAN (the function), along with modifier / string arguments to extract the numeric data desired. The DOC is pretty self-explanatory as far as the various coding techniques and results / behavior desired.
07-28-2015 07:35 PM
string juggling, just like spinning plates
%let length_date = %length(mmddccyy);
%let position_dot =%index(&mystr,.);
%let number =
%substr(&mystr,%eval(&position_dot - &length_date),&length_date);
*eval not necessary in previous line;
%let date = %sysfunc(mdy
%put &=date;*is.a SAS date;
%put %sysfunc(putn(&date ,weekdate29.));
see also the page and paper Macro Loops with Dates
Need further help from the community? Please ask a new question.