I would like to create a macro that would create a sort variable for a dotted decimal string (Chap: 1.2.3.4 or IP: 192.168.1.101) so that, for example, 1.10.1 would appear after 1.2.1 .
I was unable to find anything similar in the forums.
I can do this in Base SAS, but don't remember how to pass a data step variable into a macro.
I created the test data set with:
data test ;
   input chapter $ ;
cards;
1.2.2.5
1.2.10.5
2.10
1.35
1.2.5
2.587
2.3.9.8
run ;
I created the data step version as:
data test1 ;
	set test ;
	array part{5} $3 ;
	length chapters $19 ;
	do i= 1 to countc(chapter,".")+1 ;
  		part(i)=scan(chapter,i);
 		part(i)=translate(right(part(i)),"0"," ");
		chapters=trim(chapters)||"."||part(i);
		end;
	chapters=substr(chapters,3);
	run ;
(the output gives a clearer idea of where I'm heading with this)
I created a macro that almost does what I'm looking for:
%macro multidec(string);
	%local part sect padc ;
	%let part=1 ;
	%let sect = %scan(&string, ∂) ;
	%let padc=00 ;
	%let mult= ;
	%do %while(§ ne );
 		%let sect=%substr(&padc§,%length(§)) ;
		%let mult=&mult..§ ;
		%let part=%eval(∂ + 1);
		%let sect=%scan(&string, ∂) ;
		%end;
	%let mult=%substr(&mult,2) ;
	%put &mult ;
	%mend ;
%multidec(1.2.3.4) ;
Where I hang up is passing the value of chapter (1.2.3.4) into a macro. I'd like to pass in variable name from a dataset as well as the name of the new variable to be created, something like %multidec(chapter,chapters).
Any suggestions you'd care to offer would be welcome. Especially if someone has already done this ...