Published on :
ETL MIXTE

Management of Location Data and SAS Utility Macros

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The entire code consists of a main script that uses a DATA Step with `datalines4` to create location data in `work.Location`, then appends it to a permanent dataset `productn.Location` via `PROC APPEND`. It also contains the definition of two SAS© macros: `%macro_without_brief_tag`, a simple test macro that displays its argument, and `%mm_getdetails`, a more complex macro for querying the SAS© metadata server to extract attributes and associations of a given metadata object URI.
Data Analysis

Type : MIXTE


The main script creates data internally via `datalines4`. The `%mm_getdetails` macro interacts with the SAS metadata server to retrieve system information (metadata). The `%macro_without_brief_tag` macro operates on internally passed arguments and does not process external data.

1 Code Block
DATA STEP Data
Explanation :
This DATA Step block creates the `work.Location` dataset. It defines variable attributes (length, format, label) and reads the data provided in the `datalines4` section. `datalines4` allows integrating data directly into the script, formatted as CSV with a comma delimiter. The `DATETIME22.3` format indicates that the date is stored as a SAS numeric value, representing the date and time with millisecond precision.
Copied!
1DATA work.Location ;
2attrib
3LocationID LENGTH= 8 FORMAT=6. label="LocationID"
4Name LENGTH= $100 FORMAT=$100. label="Name"
5CostRate LENGTH= 8 FORMAT=12.4 label="CostRate"
6Availability LENGTH= 8 FORMAT=10.2 label="Availability"
7ModifiedDate LENGTH= 8 FORMAT=DATETIME22.3 label="ModifiedDate"
8;
9INFILE CARDS dsd delimiter=',';
10INPUT
11 LocationID
12 Name :$char.
13 CostRate
14 Availability
15 ModifiedDate
16;
17datalines4;
181,Tool Crib,0,0,1525132800
192,Sheet Metal Racks,0,0,1525132800
203,Paint Shop,0,0,1525132800
214,Paint Storage,0,0,1525132800
225,Metal Storage,0,0,1525132800
236,Miscellaneous Storage,0,0,1525132800
247,Finished Goods Storage,0,0,1525132800
2510,Frame Forming,22.5,96,1525132800
2620,Frame Welding,25,108,1525132800
2730,Debur and Polish,14.5,120,1525132800
2840,Paint,15.75,120,1525132800
2945,Specialized Paint,18,80,1525132800
3050,Subassembly,12.25,120,1525132800
3160,Final Assembly,12.25,120,1525132800
32;;;;
33RUN;
2 Code Block
PROC APPEND
Explanation :
`PROC APPEND` is used to append all observations from the `work.Location` dataset (previously created) to the end of the `productn.Location` dataset. This procedure is efficient for adding new rows to an existing table without having to recreate it entirely. The `productn.Location` table is assumed to exist or be created by another process.
Copied!
1 
2PROC APPEND base=productn.Location
3DATA=work.Location;
4RUN;
5 
3 Code Block
MACRO macro_without_brief_tag
Explanation :
This block defines the SAS macro `%macro_without_brief_tag`. It takes an argument `i_desc` and displays it directly in the SAS log via `%PUT`. This simple macro is primarily intended for testing, debugging, or displaying the value of a macro variable.
Copied!
1%MACRO macro_without_brief_tag (i_desc);
2%put &i_desc.;
3%MEND macro_without_brief_tag;
4 
4 Code Block
MACRO mm_getdetails Data
Explanation :
This macro, `%mm_getdetails`, is designed to extract detailed information (attributes and associations) from a SAS metadata object URI. It takes a URI as input and two optional output datasets (`outattrs` and `outassocs`). The first DATA Step block iterates through the associations of the specified URI using the `metadata_getnasl` and `metadata_getnasn` functions, then extracts names via `metadata_getattr`, storing this information in `&outassocs`. The second DATA Step block extracts properties and attributes of the URI using `metadata_getnprp` and `metadata_getnatr`, storing the details in `&outattrs`. Each dataset is then sorted by `PROC SORT` according to the provided options.
Copied!
1%macro mm_getdetails(uri
2 ,outattrs=work.attributes
3 ,outassocs=work.associations
4 ,sortoptions=
5)/*/STORE SOURCE*/;
6 
7DATA &outassocs;
8 keep assoc assocuri name;
9 LENGTH assoc assocuri name $256;
10 call missing(of _all_);
11 rc1=1;n1=1;
12 DO while(rc1>0);
13 /* Walk through all possible associations of this object. */
14 rc1=metadata_getnasl("&uri",n1,assoc);
15 rc2=1;n2=1;
16 DO while(rc2>0);
17 /* Walk through all the associations on this machine object. */
18 rc2=metadata_getnasn("&uri",trim(assoc),n2,assocuri);
19 IF (rc2>0) THEN DO;
20 rc3=metadata_getattr(assocuri,"Name",name);
21 OUTPUT;
22 END;
23 call missing(name,assocuri);
24 n2+1;
25 END;
26 n1+1;
27 END;
28RUN;
29PROC SORT &sortoptions;
30 BY assoc name;
31RUN;
32 
33DATA &outattrs;
34 keep type name value;
35 LENGTH type $4 name $256 value $32767;
36 rc1=1;n1=1;type='Prop';name='';value='';
37 DO while(rc1>0);
38 rc1=metadata_getnprp("&uri",n1,name,value);
39 IF rc1>0 THEN OUTPUT;
40 n1+1;
41 END;
42 rc1=1;n1=1;type='Attr';
43 DO while(rc1>0);
44 rc1=metadata_getnatr("&uri",n1,name,value);
45 IF rc1>0 THEN OUTPUT;
46 n1+1;
47 END;
48RUN;
49PROC SORT &sortoptions;
50 BY type name;
51RUN;
52 
53%mend mm_getdetails;
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.
Copyright Info : Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de. This file is part of SASUnit, the unit testing framework for SAS(R) programs. For copyright information and terms of use under the GNU Lesser General Public License, see the included README.md file or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.