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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.