Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_getcols.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Creates a dataset with all metadata columns for a particular table
4  @details
5 
6  usage:
7 
8  %mm_getcols(tableuri=A5X8AHW1.B40001S5)
9 
10  @param outds the dataset to create that contains the list of columns
11  @param uri the uri of the table for which to return columns
12 
13  @returns outds dataset containing all columns, specifically:
14  - colname
15  - coluri
16  - coldesc
17 
18  @version 9.2
19  @author Allan Bowe
20 
21 **/
22 
23 %macro mm_getcols(
24  tableuri=
25  ,outds=work.mm_getcols
26 )/*/STORE SOURCE*/;
27 
28 data &outds;
29  keep col: SAS:;
30  length assoc uri coluri colname coldesc SASColumnType SASFormat SASInformat
31  SASPrecision SASColumnLength $256;
32  call missing (of _all_);
33  uri=symget('tableuri');
34  n=1;
35  do while (metadata_getnasn(uri,'Columns',n,coluri)>0);
36  rc3=metadata_getattr(coluri,"Name",colname);
37  rc3=metadata_getattr(coluri,"Desc",coldesc);
38  rc4=metadata_getattr(coluri,"SASColumnType",SASColumnType);
39  rc5=metadata_getattr(coluri,"SASFormat",SASFormat);
40  rc6=metadata_getattr(coluri,"SASInformat",SASInformat);
41  rc7=metadata_getattr(coluri,"SASPrecision",SASPrecision);
42  rc8=metadata_getattr(coluri,"SASColumnLength",SASColumnLength);
43  output;
44  call missing(colname,coldesc,SASColumnType,SASFormat,SASInformat
45  ,SASPrecision,SASColumnLength);
46  n+1;
47  end;
48 run;
49 proc sort;
50  by colname;
51 run;
52 
53 %mend;