Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_distinctfmtvalues.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Creates a dataset containing distinct _formatted_ values
4 @details If no format is supplied, then the original value is used instead.
5 There is also a dependency on other macros within the Macro Core library.
6 Usage:
7
8 %mp_distinctfmtvalues(libds=sashelp.class,var=age,outvar=age,outds=test)
9
10 @param [in] libds= () input dataset
11 @param [in] var= (0) variable to get distinct values for
12 @param [out] outvar= (formatteed_value) variable to create.
13 @param [out] outds= (work.mp_distinctfmtvalues) dataset to create.
14 @param [in] varlen= (2000) length of variable to create
15
16 @version 9.2
17 @author Allan Bowe
18
19**/
20
21%macro mp_distinctfmtvalues(
22 libds=
23 ,var=
24 ,outvar=formatted_value
25 ,outds=work.mp_distinctfmtvalues
26 ,varlen=2000
27)/*/STORE SOURCE*/;
28
29 %local fmt vtype;
30 %let fmt=%mf_getvarformat(&libds,&var);
31 %let vtype=%mf_getvartype(&libds,&var);
32
33 proc sql;
34 create table &outds as
35 select distinct
36 %if &vtype=C & %trim(&fmt)=%str() %then %do;
37 &var
38 %end;
39 %else %if &vtype=C %then %do;
40 put(&var,&fmt)
41 %end;
42 %else %if %trim(&fmt)=%str() %then %do;
43 put(&var,32.)
44 %end;
45 %else %do;
46 put(&var,&fmt)
47 %end;
48 as &outvar length=&varlen
49 from &libds;
50%mend mp_distinctfmtvalues;