Fileref in macro

filename and %inc

You can access several files or members from this storage location by listing them in parentheses after the fileref in a single %INCLUDE statement. Separate filenames with a comma or a blank space. The following %INCLUDE statement demonstrates this method:

filename student ‘/data/student/home/files/’;
%inc student(sasprog1);
%inc student(sasprog2);
%inc student(sasprog3);

%inc student(sasprog1, sasprog2, sasprog3);

If you associate a fileref with an aggregate storage location, use the fileref, followed in parentheses by an individual filename, to read from or write to any of the individual external files that are stored there.
In this example, each DATA step reads from an external file (REGION1 and REGION2, respectively) that is stored in the same aggregate storage location and that is referenced by the fileref SALES.

filename sales ‘aggregate-storage-location’;

data total1;
infile sales(region1);
input machine $ jansales febsales marsales;
totsale=jansales+febsales+marsales;
run;

data total2;
infile sales(region2);
input machine $ jansales febsales marsales;
totsale=jansales+febsales+marsales;
run;

 

 

SAS system options for debugging Macro

reference: http://studysas.blogspot.ca/2009/08/macro-debugging-optionsmprint-mlogic.html

reference: support.sas.com

mlogic, mprint, mfile, symbolgen

mlogic

Use MLOGIC to debug macros. Each line generated by the MLOGIC option is identified with the prefix MLOGIC(macro-name):. If MLOGIC is in effect and the macro processor encounters a macro invocation, the macro processor displays messages that identify the beginning of macro execution; values of macro parameters at invocation; execution of each macro program statement; whether each %IF condition is true or false; the ending of macro execution.

mprint

The MPRINT option displays the text generated by macro execution. Each SAS statement begins a new line. Each line of MPRINT output is identified with the prefix MPRINT(macro-name):, to identify the macro that generates the statement. Tokens that are separated by multiple spaces are printed with one intervening space.  You can direct MPRINT output to an external file by also using the MFILE option and assigning the fileref MPRINT to that file.

mfile

The MPRINT option must also be in effect to use MFILE, and an external file must be assigned the fileref MPRINT. Macro-generated code that is displayed by the MPRINT option in the SAS log during macro execution is written to the external file referenced by the fileref MPRINT.
If MPRINT is not assigned as a fileref or if the file cannot be accessed, warnings are written to the SAS log and MFILE is set to off. To use the feature again, you must specify MFILE again and assign the fileref MPRINT to a file that can be accessed.

options mfile mprint;
filename mprintdebugmac‘;

symbolgen

displays the results of resolving macro variable references.SYMBOLGEN also indicates when a double ampersand (&& ) resolves to a single ampersand (& ).

 

SAS Sgplot

Purpose: change marker and line attributes.

source code: http://support.sas.com/documentation/cdl/en/grstatproc/67909/HTML/default/viewer.htm#n1jkqnmk6y6ms9n1b2vvubyzqd4a.htm#n0drw4zpeqxun6n1szhz24ebw0qx

Shortcoming: work on 9.4 but not the previous versions.

data myclass;
set sashelp.class;
run;
proc sgplot data=myclass;
series x=name y=weight /markers markerattrs = (size=10pt)
group=sex;
run;

9-13-2016-2-29-08-pm

/* Create the data set.  */
data myclass;
set sashelp.class;
length type $10;
if age > 12 then type=’Teen’;
else type=’Pre-Teen’;
label type=”Age Group”;
run;
/* Create the attribute map. */
data mymap;
retain id “mytest”;
input value $ markersymbol $;
datalines;
Pre-Teen triangle
Teen square
;
run;
proc sgplot data=myclass dattrmap=mymap;
series x=name y=weight / markers
markerattrs=(size=10pt)
group=sex name=”a”
groupms=type msattrid=mytest;
keylegend “a” / type=markersymbol;
keylegend “a” / type=linecolor;
run;

SAS String Functions

SCAN/COMPRESS/COMPBL

SCAN(string, count<,charlist <,modifiers>>)

Column: deptname
‘AB-Department X’
‘CD-Department Y’

data faculty;
set admin1516;
where divdesc = “Faculties”;
length fac $4.;
fac = scan(deptname, 1, ‘-‘);
run;

New Column: fac
‘AB’
‘CD’

COMPRESS(source<, chars><, modifiers>)

compress all the blanks

a= ‘A  B    C  D’

b= compress(a)

results for b is : ‘ABCD’

COMPBL: removes multiple blanks

a= ‘A  B  C D ‘

b= compbl(a)

results for b is : ‘A B C D’

 

 

Remote submit and library

libname   datalib   remote '/directory1/folder' server=servername.spawner; run;

ORACLE DATA

libname datalib oracle user=username password="password" schema=schemaname;

Start remote process.

rsubmit;

Download dataset to local.

proc download data=serverdataset; run;
proc download data=serverdataset out=locallib.dataset; run;

End remote process from the client session.

endrsubmit;

 

 

 

Delete dataset

Library has to be specified using library= option.  Use “delete libraryname.tablea” doesn’t work. Option “noprint” causes error.

rsubmit;
proc datasets library=libraryname nodetails nolist;
delete tablea;
run;
endrsubmit;