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 <h4> SAS Macros </h4>
17 @li mf_getvarformat.sas
18 @li mf_getvartype.sas
19
20 @version 9.2
21 @author Allan Bowe
22
23**/
24
25%macro mp_distinctfmtvalues(
26 libds=
27 ,var=
28 ,outvar=formatted_value
29 ,outds=work.mp_distinctfmtvalues
30 ,varlen=2000
31)/*/STORE SOURCE*/;
32
33 %local fmt vtype;
34 %let fmt=%mf_getvarformat(&libds,&var);
35 %let vtype=%mf_getvartype(&libds,&var);
36
37 proc sql;
38 create table &outds as
39 select distinct
40 %if &vtype=C & %trim(&fmt)=%str() %then %do;
41 &var
42 %end;
43 %else %if &vtype=C %then %do;
44 put(&var,&fmt)
45 %end;
46 %else %if %trim(&fmt)=%str() %then %do;
47 put(&var,32.)
48 %end;
49 %else %do;
50 put(&var,&fmt)
51 %end;
52 as &outvar length=&varlen
53 from &libds;
54%mend mp_distinctfmtvalues;