Sas Macro To Split A Macro Variables Values To Multiple Macro Variables Values And Also Get The Split Count Into Another Variable

  • Uploaded by: SASTechies
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sas Macro To Split A Macro Variables Values To Multiple Macro Variables Values And Also Get The Split Count Into Another Variable as PDF for free.

More details

  • Words: 234
  • Pages: 4
When you are dealing with macros a lot there would be a need to split a macro variables values to multiple macro variables values and also get the split count into another variable…. Try this macro for those purposes….

/** Explanation of the Macro Parameters... macvar - name of the macro variable that has info to be splitted.. prefix - prefix of the macro vars to be created in sequence order... splitcnt - name of the macro vars to store the length of the macro variable dlm - delimiter in the string (default is blank i.e. ' ') e.g. %splitmacroval(str1,pre,strcnt,dlm=' '); look below for the example.. **/ %macro splitmacroval(macvar,prefix,splitcnt,dlm=' '); %global &splitcnt; /*create the global variable for storing the splitcount*/ %let num=1; /*initialize a counter variable*/ %global &prefix# /*create the global variable for storing the first split*/ %let &prefix&num=%scan(&&&macvar,&num,&dlm); /*Scan the first value*/

%do %while(&&&prefix&num ne ); %let num=%eval(&num + 1);/*increment the counter*/ %global &prefix# /*create the global variable*/ %let &prefix&num=%scan(&&&macvar,&num,&dlm); /*scan the next value*/ %end; %let &splitcnt=%eval(&num - 1); /*Store the split count to the macro variable reqd*/ /** Remove the comment's to check the values %put &splitcnt=&&&splitcnt; %do i=1 %to %eval(&&&splitcnt + 0); %put &&prefix&&&splitcnt = &&prefix&&&splitcnt; %end; */ %mend splitmacroval; An Eg… %let str1=he she me to 3 "some"; %splitmacroval(str1,pre,strcnt,dlm=' '); %put pre1=&pre1 pre2=&pre2 pre3=&pre3 pre4=&pre4 pre5=&pre5 pre6=&pre6 ; %put strcnt=&strcnt;

Would produce this in the Log…

Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-split-macrovariables.html

Related Documents


More Documents from ""