- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
input_variables
if a
if b
if c
And another dataset with expression
expression
"""= 10 then pk=100;"
"""= 20 then pk=300;"
"""= 30 then pk=500;"
"""= 40 then pk=600;"
"""= 50 then pk=800;"
"""= 60 then pk=900;"
"""= 70 then pk=1000;"
"""= 80 then pk=1300;"
"""= 90 then pk=1500;"
"""= 100 then pk=1800;"
Now I want output as iteration of variable for all expression. Here is how it should look like
"if a""= 10 then pk=100;"
"if a""= 20 then pk=300;"
"if a""= 30 then pk=500;"
"if a""= 40 then pk=600;"
"if a""= 50 then pk=800;"
"if a""= 60 then pk=900;"
"if a""= 70 then pk=1000;"
"if a""= 80 then pk=1300;"
"if a""= 90 then pk=1500;"
"if a""= 100 then pk=1800;"
"if b""= 10 then pk=100;"
"if b""= 20 then pk=300;"
"if b""= 30 then pk=500;"
"if b""= 40 then pk=600;"
"if b""= 50 then pk=800;"
"if b""= 60 then pk=900;"
"if b""= 70 then pk=1000;"
"if b""= 80 then pk=1300;"
"if b""= 90 then pk=1500;"
"if b""= 100 then pk=1800;"
"if c""= 10 then pk=100;"
"if c""= 20 then pk=300;"
"if c""= 30 then pk=500;"
"if c""= 40 then pk=600;"
"if c""= 50 then pk=800;"
"if c""= 60 then pk=900;"
"if c""= 70 then pk=1000;"
"if c""= 80 then pk=1300;"
"if c""= 90 then pk=1500;"
"if c""= 100 then pk=1800;"
Any help is really appreciated
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Seems like a strange idea, but let's work through it so you can learn how this might work.
First let's be clearer about what we have. I am assuming you have two datasets. So let's present some code that will create those datasets. Let's call them LEFT and RIGHT.
data left;
input input_variables $50. ;
cards;
if a
if b
if c
;
data right;
input expression $50. ;
cards4;
= 10 then pk=100;
= 20 then pk=300;
= 30 then pk=500;
= 40 then pk=600;
= 50 then pk=800;
= 60 then pk=900;
= 70 then pk=1000;
= 80 then pk=1300;
= 90 then pk=1500;
= 100 then pk=1800;
;;;;
The simplest way to get all combinations is to use PROC SQL to perform a Cartesian product of the two sets.
Now I think you are saying you want to concatenate the two variables into a new character variable.
proc sql;
create table want as
select a.input_variables
, b.expression
, catx(' ',a.input_variables,b.expression) as statement
from left a
, right b
;
quit;
So now you have a dataset with three variables.
What do you want do with this next?
Do you want to somehow run those statements? If so what data do you want to run them against?
Are you sure you want run all three of these statements in the same step?
if a = 10 then pk=100;
if b = 10 then pk=100;
if c = 10 then pk=100;
If so the order you run them might determine what value PK ends up having.
So perhaps it would help a lot if you took a step back and explained the overall picture of what you are trying to do. Perhaps treating code as data is not the easiest way to get from what you have to what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Seems like a strange idea, but let's work through it so you can learn how this might work.
First let's be clearer about what we have. I am assuming you have two datasets. So let's present some code that will create those datasets. Let's call them LEFT and RIGHT.
data left;
input input_variables $50. ;
cards;
if a
if b
if c
;
data right;
input expression $50. ;
cards4;
= 10 then pk=100;
= 20 then pk=300;
= 30 then pk=500;
= 40 then pk=600;
= 50 then pk=800;
= 60 then pk=900;
= 70 then pk=1000;
= 80 then pk=1300;
= 90 then pk=1500;
= 100 then pk=1800;
;;;;
The simplest way to get all combinations is to use PROC SQL to perform a Cartesian product of the two sets.
Now I think you are saying you want to concatenate the two variables into a new character variable.
proc sql;
create table want as
select a.input_variables
, b.expression
, catx(' ',a.input_variables,b.expression) as statement
from left a
, right b
;
quit;
So now you have a dataset with three variables.
What do you want do with this next?
Do you want to somehow run those statements? If so what data do you want to run them against?
Are you sure you want run all three of these statements in the same step?
if a = 10 then pk=100;
if b = 10 then pk=100;
if c = 10 then pk=100;
If so the order you run them might determine what value PK ends up having.
So perhaps it would help a lot if you took a step back and explained the overall picture of what you are trying to do. Perhaps treating code as data is not the easiest way to get from what you have to what you want.