BookmarkSubscribeRSS Feed
draroda
Fluorite | Level 6

Hi All,

 

I am trying to create variables to convert value from Numeric to Character depending on VTYPE values but seems things are not working and log is having issues.  

 

Can you please help me out on what is going wrong ?

 

 

 

Below is log issues:

 

36 %check(name);
MLOGIC(CHECK): Beginning execution.
MLOGIC(CHECK): Parameter VAR has value name
MPRINT(CHECK): data check;
MPRINT(CHECK): set sashelp.class;
SYMBOLGEN: Macro variable VAR resolves to name
MPRINT(CHECK): typ = vtype(name);
SYMBOLGEN: Macro variable VAR resolves to name
SYMBOLGEN: Macro variable VAR resolves to name
NOTE: Line generated by the invoked macro "CHECK".
36 data check; set sashelp.class; typ = vtype(&var); if typ="n" then new_&var=put(&var,best.); else new_&var=strip(&var); run;
_____
484
NOTE 484-185: Format $BEST was not found or could not be loaded.

MPRINT(CHECK): if typ="n" then new_name=put(name,best.);
SYMBOLGEN: Macro variable VAR resolves to name
SYMBOLGEN: Macro variable VAR resolves to name
MPRINT(CHECK): else new_name=strip(name);
MPRINT(CHECK): run;

The SAS System 08:48 Friday, December 13, 2019

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CHECK has 19 observations and 7 variables.
NOTE: Compressing data set WORK.CHECK increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

MLOGIC(CHECK): Ending execution.
37 %check(age);
MLOGIC(CHECK): Beginning execution.
MLOGIC(CHECK): Parameter VAR has value age
MPRINT(CHECK): data check;
MPRINT(CHECK): set sashelp.class;
SYMBOLGEN: Macro variable VAR resolves to age
MPRINT(CHECK): typ = vtype(age);
SYMBOLGEN: Macro variable VAR resolves to age
SYMBOLGEN: Macro variable VAR resolves to age
MPRINT(CHECK): if typ="n" then new_age=put(age,best.);
SYMBOLGEN: Macro variable VAR resolves to age
SYMBOLGEN: Macro variable VAR resolves to age
MPRINT(CHECK): else new_age=strip(age);
MPRINT(CHECK): run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
37:1
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CHECK has 19 observations and 7 variables.
NOTE: Compressing data set WORK.CHECK increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

MLOGIC(CHECK): Ending execution.
38 %check(height);
MLOGIC(CHECK): Beginning execution.
MLOGIC(CHECK): Parameter VAR has value height
MPRINT(CHECK): data check;
MPRINT(CHECK): set sashelp.class;
SYMBOLGEN: Macro variable VAR resolves to height
MPRINT(CHECK): typ = vtype(height);
SYMBOLGEN: Macro variable VAR resolves to height
SYMBOLGEN: Macro variable VAR resolves to height
MPRINT(CHECK): if typ="n" then new_height=put(height,best.);
SYMBOLGEN: Macro variable VAR resolves to height
SYMBOLGEN: Macro variable VAR resolves to height
MPRINT(CHECK): else new_height=strip(height);
MPRINT(CHECK): run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
38:1
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CHECK has 19 observations and 7 variables.
NOTE: Compressing data set WORK.CHECK increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
The SAS System 08:48 Friday, December 13, 2019

NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

MLOGIC(CHECK): Ending execution.

 

 

Thanks 

%macro check (var);
data check;
set sashelp.class;
typ = vtype(&var);
if typ="n" then 
new_&var=put(&var,best.);
else new_&var=strip(&var);
run;
%mend;
options symbolgen mlogic mprint;
%check(name);
%check(age);
%check(height);
 
3 REPLIES 3
Tom
Super User Tom
Super User

A data step compiles ALL of the code you give it. Even the part inside an branch that can never end up executing.

 

Your macro is not really very useful as presented but let's use it as an example of ways to handle this type of issue.  One way is to just write code that does not depend on knowing the variables type before the data step starts running.  For example by using VVALUE() function to get the formatted value.

data check;
  set sashelp.class;
  new_NAME=vvalue(NAME);
run;

The other is to find out the type and use that to drive MACRO logic that generates different code for the data step.

data _null_;
  set sashelp.class;
  call symputx('typ',vtype(NAME));
  stop;
run;
data check;
  set sashelp.class;
%if N=&typ %then %do;
  new_NAME=put(NAME,best32.);
%end;
%else %do;
  new_NAME=strip(NAME);
%end;
run;

 

PaigeMiller
Diamond | Level 26

If you look at any of these data sets, you will see that the values of variable TYP are capitalized. So 

 

if typ="n" ...

will always fail. You need

 

if typ='N' ...

Also, you want 

 

if typ="N" then new_&var=put(&var,8.);

which will eliminate the other error.

 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2869 views
  • 1 like
  • 3 in conversation