shecode
shecode

Reputation: 1726

How do I use a function within the PUT function in SAS

How do I print out the format of a variable of interest? Note i've simplified my example

%let var_ = '1sep2014' %put | VARTYPE(&var_)

I'd expect this to return the format type in the log but it just returns | VARTYPE(&1sep2014)

Upvotes: 0

Views: 518

Answers (1)

SRSwift
SRSwift

Reputation: 1710

There is no way simple way to find a format that matches a string. As mjsqu says the function vartype does not do what you are hoping.

However, if you wish to use a datastep function within a macro variable assignment or %put statement you can use %sysfunc() macro function.

Code:

/* Assignment of a string to a macro variable*/
/* SAS date literal "DDMMYYYY"d will be automatically evaluated later */
%let v1 = "01sep2014"d;
%put &v1;

/* Use off a datastep function in an assignment, evaluates date literal as number */
%let v2 = %sysfunc(putn(&v1, date9.));
%put &v2;

/* Use of a datastep function in a %put statement */
%put %sysfunc(putn(&v1, yymmdd10.));

Output:

"01sep2014"d
01SEP2014
2014-09-01

Upvotes: 2

Related Questions