Skip to content

Commit

Permalink
Update for SAS Packages Framework, version 20241027
Browse files Browse the repository at this point in the history
  • Loading branch information
yabwon committed Oct 28, 2024
1 parent ba774cb commit 8eac1bb
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 2 deletions.
7 changes: 7 additions & 0 deletions PSDv5/!to_ignore/ignore.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
proc print data=supercool label;
run;
/*
This comment will be populated to ALL files
in ALL directories.
*/
17 changes: 17 additions & 0 deletions PSDv5/001_macro/dcmacro.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
/* dcmacro macro */

%macro dcmacro(hero)/secure;

%put Hey %superq(hero)! Why so serious?!?!;

%mend dcmacro;

/*
%dcmacro(BATMAN)
*/

/*
This comment will be populated to ALL files
in ALL directories.
*/
51 changes: 51 additions & 0 deletions PSDv5/001_macro/marvelmacro.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* File generated with help of SAS Packages Framework, version 20241027. */

/* marvelmacro macro */

%macro marvelmacro(hero)/secure;

%if %superq(hero)=HULK %then
%do;
%put "Hulk will, Hulk will... smash you!";
%goto EOM;
%end;

%if %superq(hero)=IRONMAN %then
%do;
%put "I'm not a superhero type...";
%put "The truth is... I am Iron Man.";
%goto EOM;
%end;

%if %superq(hero)=DEADPOOL %then
%do;
%put "I'll draw a Unicorn for Logan <3 B-] <3";
%goto EOM;
%end;

%if %superq(hero)=STARLORD %then
%do;
%put "Squeak, squeak..";
%put ,.!.. ;
%put "Oh, I'm sorry. I didn't know how this machine worked.";
%goto EOM;
%end;


%put Hey %superq(hero)! Tina says: "We don't need another heeeeroooo!!!";

%EOM:
%mend marvelmacro;

/*
%marvelmacro(IRONMAN);
%marvelmacro(HULK);
%marvelmacro(STARLORD);
%marvelmacro(DEADPOOL);
%marvelmacro(BART);
*/

/*
This comment will be populated to ALL files
in ALL directories.
*/
10 changes: 10 additions & 0 deletions PSDv5/001_macro/supercool.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* File generated with help of SAS Packages Framework, version 20241027. */

%macro supercool(you,data,what);
%put Hey %superq(you)! My %superq(data) is %superq(what) than your %superq(data)!;
%mend supercool;

/*
This comment will be populated to ALL files
in ALL directories.
*/
9 changes: 9 additions & 0 deletions PSDv5/002_formats/fastformat.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
value $ fastformat (default=8)
"VIN" = "Diesel"
other = "Gasoline"
;
/*
This comment will be populated to ALL files
in ALL directories.
*/
16 changes: 16 additions & 0 deletions PSDv5/002_formats/infamous.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
invalue infamous (default=8 upcase)
"THE GOOD" = 1
"THE BAD" = -1
"THE UGLY" = 0
other = .
;
value infamous (default=8)
0<-HIGH = "THE GOOD"
LOW-<0 = "THE BAD"
other = "THE UGLY"
;
/*
This comment will be populated to ALL files
in ALL directories.
*/
17 changes: 17 additions & 0 deletions PSDv5/003_functions/furiousfunction.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
function furiousfunction(user $,value) $;
length result $ 128;

result = catx(" ",
user,
"is",
put(value/100, percent12.),
put(upcase(user), $fastformat.)
);

return(result);
endfunc;
/*
This comment will be populated to ALL files
in ALL directories.
*/
8 changes: 8 additions & 0 deletions PSDv5/003_functions/supercool.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
function supercool(data $) $;
return(catx(" ", quote(data), "is Super Cool!"));
endfunc;
/*
This comment will be populated to ALL files
in ALL directories.
*/
14 changes: 14 additions & 0 deletions PSDv5/004_data/f_and_f.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
data F_and_F;
infile cards dlm=',';
input name $ value;
text = furiousfunction(name, value);
cards;
Vin,100
The Rock,99
;
run;
/*
This comment will be populated to ALL files
in ALL directories.
*/
15 changes: 15 additions & 0 deletions PSDv5/004_data/sergio.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
data Sergio;
infile cards dlm=",";
input x :infamous. y;
format y infamous.;
cards;
the good, 42
THE BAD, -17
tHe UgLy, 0
;
run;
/*
This comment will be populated to ALL files
in ALL directories.
*/
13 changes: 13 additions & 0 deletions PSDv5/005_lazydata/supercool.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
/* supercool data */

data supercool;
dataCool = "Data, data cool! This data is Super Cool!";
label
dataCool = "Label for Super Cool data";
run;

/*
This comment will be populated to ALL files
in ALL directories.
*/
24 changes: 24 additions & 0 deletions PSDv5/999_test/test.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* File generated with help of SAS Packages Framework, version 20241027. */
%marvelmacro(IRONMAN);
%marvelmacro(HULK);
%marvelmacro(STARLORD);
%marvelmacro(DEADPOOL);
%marvelmacro(BART);
%dcmacro(BATMAN)
/* */
proc print data=F_and_F noobs;
var text;
run;
proc print data=Sergio label;
run;
%supercool(Python, code, faster)

%supercool(Excel, table, bigger)
data _null_;
x = supercool("WUSS Conference 2023");
put x=;
run;
/*
This comment will be populated to ALL files
in ALL directories.
*/
57 changes: 55 additions & 2 deletions Share your code with SAS Packages - a Hands-on-Workshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ The closest one to the idea presented here is the `SAS/IML` which offers (limite
A **SAS package** is an automatically generated, single, stand alone `zip` file containing organized and ordered code structures, created by the developer and extended with additional automatically generated "driving" files (i.e. description, metadata, load, unload, and help files).
The purpose of a package is to be a simple, and easy to access, code sharing medium, which allows: on the one hand, to separate the code complex dependencies created by the developer from the user experience with the final product and, on the other hand, reduce developer's and user's unnecessary frustration related to the deployment (installation) process.

The **SAS Packages Framework** is a "pack" of macros, which allows the *use* and *development* of SAS packages. At the moment there are 11 (eleven) macros in the framework.
The **SAS Packages Framework** is a "pack" of macros, which allows the *use* and *development* of SAS packages. At the moment there are 12 (twelve) macros in the framework.

Ten of them dedicated for users:

Expand All @@ -209,10 +209,12 @@ Ten of them dedicated for users:

- [`%extendPackagesFileref()`](https://github.com/yabwon/SAS_PACKAGES/blob/main/SPF/SPFinit.md#extendpackagesfileref)

and one dedicated to developers:
and two dedicated to developers:

- [`%generatePackage() `](https://github.com/yabwon/SAS_PACKAGES/blob/main/SPF/SPFinit.md#generatepackage )

- [`%splitCodeForPackage() `](https://github.com/yabwon/SAS_PACKAGES/blob/main/SPF/SPFinit.md#splitcodeforpackage )

The above list contains links to the documentation of each macro, similar documentation in a text form can be displayed in the SAS log by running the following code:

```sas
Expand Down Expand Up @@ -1526,6 +1528,8 @@ The [**Package Storage Directory version 1**](./PSDv1 "Package Storage Directory

OK, we did it! The most laboursome part of the work is behind us.

[**NOTE:**] If you have a "one big code file" and think splitting it in those multiple-separate-files-and-subdirectories looks to painful for you to go further with creating a package, fear not! In the ["Few other details"](#few-other-details) section you can find description and use case example of the `%splitCodeForPackage()` *utility* macro that can help you make the process easier.

#### The description

The description file contains package "metadata". Its simple structure is based on key-value pairs separated by a colon (`:`) and a block of the description text surrounded by `DESCRIPTION START:` and `DESCRIPTION END:` tags.
Expand Down Expand Up @@ -2139,6 +2143,55 @@ filename packages "/path/to/my/packages";
%ICEloadPackage(myPackage)
```



### It's to laboursome and I'm lazy

This section presents a utility macro that makes the splitting a "one big code" file into a package structure process much easier and less laborious.

The `%splitCodeForPackage()` utility macro allows us to take one big code file, and after adding some `tags` to it, split the content of the file into a package structure (i.e. files and directories).

The tagging process is very simple. Each code snippet you want to "redirect" to a particular file you mark by
`/*##$##-code-block-start-##$## 99_type(object) */`
and
`/*##$##-code-block-end-##$## 99_type(object) */` tags, for example:

```sas
/*##$##-code-block-start-##$## 01_macro(abc) */
%macro abc();
%put I am "abc".;
%mend abc;
/*##$##-code-block-end-##$## 01_macro(abc) */
```

Tags can overlap or be nested, and if we need to redirect one snippet to two files we can just surround it by
`/*##$##-code-block-start-##$## type1(object1) type2(object2) */`
and
`/*##$##-code-block-end-##$## type1(object1) type2(object2) */` block.

See the [`code for myPackage with tags.sas`](./code%20for%20myPackage%20with%20tags.sas "code for myPackage with tags.sas") file for more example.

The result of running:
```sas
%splitCodeForPackage(
codeFile="/path/to/location/of/the/code for myPackage with tags.sas"
,packagePath=/package/storage/directory)
```
code on the example file can be found in
[PSDv5](./PSDv5 "Package Storage Directory with code split by %splitCodeForPackage() macro") directory (compare it with [PSDv1](./PSDv1 "Package Storage Directory version 1")).

The `codeFile=` parameter points to the tagged file (path can in quotes or not), the `packagePath=` parameter points the location where result files should be created.

[NOTE1:] In the current version of the framework, if the process is executed multiple times files are *not* overwritten automatically. Each execution's content is "appended" to what already is in the `packagePath=` directory. If we want to start over, the `packagePath=` directory has to be manually purged from the previous execution's "leftovers".

[NOTE2:]
Each file created with help of the `%splitCodeForPackage()` macro has the following line of comment:
```sas
/* File generated with help of SAS Packages Framework, version YYYYMMDD. */
```
added at the very first line of the file.


<div align="right">
<a href='#table-of-contents'>go to ToC</a>
</div>
Expand Down
Loading

0 comments on commit 8eac1bb

Please sign in to comment.