<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Values iteration for two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Values-iteration-for-two-datasets/m-p/933059#M366998</link>
    <description>&lt;P&gt;Seems like a strange idea, but let's work through it so you can learn how this might work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's be clearer about what we have.&amp;nbsp; I am assuming you have two datasets.&amp;nbsp; So let's present some code that will create those datasets.&amp;nbsp; Let's call them LEFT and RIGHT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The simplest way to get all combinations is to use PROC SQL to perform a Cartesian product of the two sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I think you are saying you want to concatenate the two variables into a new character variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you have a dataset with three variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want do with this next?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to somehow run those statements?&amp;nbsp; If so what data do you want to run them against?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you want run all three of these statements in the same step?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a = 10 then pk=100;
if b = 10 then pk=100;
if c = 10 then pk=100;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so the order you run them might determine what value PK ends up having.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; Perhaps treating code as data is not the easiest way to get from what you have to what you want.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2024 20:53:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-06-19T20:53:38Z</dc:date>
    <item>
      <title>Values iteration for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Values-iteration-for-two-datasets/m-p/933056#M366997</link>
      <description>I have an input dataset as below &lt;BR /&gt;&lt;BR /&gt;input_variables&lt;BR /&gt;if a&lt;BR /&gt;if b&lt;BR /&gt;if c&lt;BR /&gt;&lt;BR /&gt;And another dataset with expression &lt;BR /&gt;expression &lt;BR /&gt;"""= 10 then pk=100;"&lt;BR /&gt;"""= 20 then pk=300;"&lt;BR /&gt;"""= 30 then pk=500;"&lt;BR /&gt;"""= 40 then pk=600;"&lt;BR /&gt;"""= 50 then pk=800;"&lt;BR /&gt;"""= 60 then pk=900;"&lt;BR /&gt;"""= 70 then pk=1000;"&lt;BR /&gt;"""= 80 then pk=1300;"&lt;BR /&gt;"""= 90 then pk=1500;"&lt;BR /&gt;"""= 100 then pk=1800;"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now I want output as iteration of variable for all expression. Here is how it should look like &lt;BR /&gt;&lt;BR /&gt;"if a""= 10 then pk=100;"&lt;BR /&gt;"if a""= 20 then pk=300;"&lt;BR /&gt;"if a""= 30 then pk=500;"&lt;BR /&gt;"if a""= 40 then pk=600;"&lt;BR /&gt;"if a""= 50 then pk=800;"&lt;BR /&gt;"if a""= 60 then pk=900;"&lt;BR /&gt;"if a""= 70 then pk=1000;"&lt;BR /&gt;"if a""= 80 then pk=1300;"&lt;BR /&gt;"if a""= 90 then pk=1500;"&lt;BR /&gt;"if a""= 100 then pk=1800;"&lt;BR /&gt;"if b""= 10 then pk=100;"&lt;BR /&gt;"if b""= 20 then pk=300;"&lt;BR /&gt;"if b""= 30 then pk=500;"&lt;BR /&gt;"if b""= 40 then pk=600;"&lt;BR /&gt;"if b""= 50 then pk=800;"&lt;BR /&gt;"if b""= 60 then pk=900;"&lt;BR /&gt;"if b""= 70 then pk=1000;"&lt;BR /&gt;"if b""= 80 then pk=1300;"&lt;BR /&gt;"if b""= 90 then pk=1500;"&lt;BR /&gt;"if b""= 100 then pk=1800;"&lt;BR /&gt;"if c""= 10 then pk=100;"&lt;BR /&gt;"if c""= 20 then pk=300;"&lt;BR /&gt;"if c""= 30 then pk=500;"&lt;BR /&gt;"if c""= 40 then pk=600;"&lt;BR /&gt;"if c""= 50 then pk=800;"&lt;BR /&gt;"if c""= 60 then pk=900;"&lt;BR /&gt;"if c""= 70 then pk=1000;"&lt;BR /&gt;"if c""= 80 then pk=1300;"&lt;BR /&gt;"if c""= 90 then pk=1500;"&lt;BR /&gt;"if c""= 100 then pk=1800;"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any help is really appreciated &lt;BR /&gt;</description>
      <pubDate>Wed, 19 Jun 2024 20:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Values-iteration-for-two-datasets/m-p/933056#M366997</guid>
      <dc:creator>yashpande</dc:creator>
      <dc:date>2024-06-19T20:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Values iteration for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Values-iteration-for-two-datasets/m-p/933059#M366998</link>
      <description>&lt;P&gt;Seems like a strange idea, but let's work through it so you can learn how this might work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's be clearer about what we have.&amp;nbsp; I am assuming you have two datasets.&amp;nbsp; So let's present some code that will create those datasets.&amp;nbsp; Let's call them LEFT and RIGHT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The simplest way to get all combinations is to use PROC SQL to perform a Cartesian product of the two sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I think you are saying you want to concatenate the two variables into a new character variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you have a dataset with three variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want do with this next?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to somehow run those statements?&amp;nbsp; If so what data do you want to run them against?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you want run all three of these statements in the same step?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a = 10 then pk=100;
if b = 10 then pk=100;
if c = 10 then pk=100;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so the order you run them might determine what value PK ends up having.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; Perhaps treating code as data is not the easiest way to get from what you have to what you want.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 20:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Values-iteration-for-two-datasets/m-p/933059#M366998</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-19T20:53:38Z</dc:date>
    </item>
  </channel>
</rss>

