This macro is designed to be invoked within a DATA Step. It analyzes a source variable (`var`) to detect the presence of numbers. If numbers are present, it constructs a sort variable (`ordVar`) by normalizing the numeric segments (likely separated by periods). It uses a macro loop to generate `tranwrd` instructions that add leading zeros (padding) to numbers from 0 to 9 surrounded by periods, thus allowing consistent alphanumeric sorting (e.g., treating '1.2' as less than '1.10').
Data Analysis
Type : CREATION_INTERNE
The code defines a software macro and does not directly load or manipulate external data during its compilation.
1 Code Block
MACRO
Explanation : Definition of the `AHGaddordvar` macro. It generates conditional `IF` logic for the DATA Step. It transforms the string by doubling the '.' delimiters and adding a '0' prefix to single digits found between these delimiters to standardize the sort format.
Copied!
%macro AHGaddordvar(var,ordVar);
%local i;
if anydigit(&var) then
do;
&ordvar='..'||trim(substr(tranwrd(&var,'.','..'),anydigit(&var)))||'..';
%do i=0 %to 9;
&ordvar=tranwrd(&ordvar,".&i..",".0&i..");
%end;
&ordvar=substr(&var,1,anydigit(&var)-1)||&ordvar;
end;
%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.