BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mike_B
Obsidian | Level 7

I have a data set, created from an Excel file, where logic is stored in a character variable named additional_logic. I am trying to resolve that logic in another variable--e.g. in the below example, TrueFlase would equal 0 or 1. I thought this would be simple, but I can't seem to find anything that works. I've tried IFN, I've tried CALL SYMPUTX + SYMGET to no avail. Any guidance is appreciated.

 

data x;
length additional_logic $50;
input additional_logic $;
datalines;
put(today(),day.)=6
put(today(),day.)^=6
;

data _null_;
set x;
call symputx('additional_logic',additional_logic);
TrueFalse=symget('additional_logic');
put TrueFalse;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

You can use DOSUBL like the example.  However it is usually better to write code that will compile the logic in a "regular" data step.  But DOSUBL is fun so...\

 

data x;
   length additional_logic $50;
   input additional_logic $;
   datalines;
day(today())=6
day(today())^=6
;;;;
%global additional_logic;
data tf;
   set x;
   todo=catx(' ','data _null_; call symputx("additional_logic",',additional_logic,'); stop; run;');
   rc = dosubl(todo);
   TrueFalse=symgetn('additional_logic');
   put _all_;
   run;
%put _user_;

 

 

Capture.PNG 

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

You can use DOSUBL like the example.  However it is usually better to write code that will compile the logic in a "regular" data step.  But DOSUBL is fun so...\

 

data x;
   length additional_logic $50;
   input additional_logic $;
   datalines;
day(today())=6
day(today())^=6
;;;;
%global additional_logic;
data tf;
   set x;
   todo=catx(' ','data _null_; call symputx("additional_logic",',additional_logic,'); stop; run;');
   rc = dosubl(todo);
   TrueFalse=symgetn('additional_logic');
   put _all_;
   run;
%put _user_;

 

 

Capture.PNG 

Mike_B
Obsidian | Level 7
Thank you. This worked great. All of the proposed solutions worked--Patrick's include file method was pretty cool--but this one allowed me to not have to write additional data steps/macros.
Astounding
PROC Star

The easiest way to apply these pieces of logic is to split the processing:  one DATA step to bring in the formulas, and a second DATA step to apply them.  Here is a simplified version (since it doesn't automate the number of formulas to apply):

 

data _null_;
length additional_logic $50;
input additional_logic $;
call symputx(cats('v', _n_), additional_logic);
datalines;
put(today(),day.)=6
put(today(),day.)^=6
;

data want;
   set have;
   TrueFalse1 = &v1;
   TrueFalse2 = &v2;
run;
andreas_lds
Jade | Level 19
Could be task for resolve function.
Patrick
Opal | Level 21

@Mike_B 

I find it personally often easiest to first generate the dynamic code into a file and then %include the file.

data fromExcel;
   length additional_logic $50;
   input additional_logic $;
   datalines;
day(today())=6
day(today())^=6
;;;;

filename codegen temp;
data _null_;
  file codegen;
/*  file print;*/
  set fromExcel;
  put 'TrueFalse_' _n_ z3. '=' additional_logic ';';
run;

data want;
  set sashelp.class;
  %include codegen / source2;
run;
filename codegen clear;

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1663 views
  • 6 likes
  • 5 in conversation