<?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 Macro variable and DATA step-Part 2 in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32832#M7952</link>
    <description>Hi All,&lt;BR /&gt;
Thanks to all for the valuable comments.This thread is more about the actual problem I  am facing.I am giving as example below.&lt;BR /&gt;
&lt;BR /&gt;
file1&lt;BR /&gt;
------&lt;BR /&gt;
id  sal  dept &lt;BR /&gt;
---  ---  ------&lt;BR /&gt;
1   200 sales&lt;BR /&gt;
2   300 purchase&lt;BR /&gt;
3   500 marketing&lt;BR /&gt;
&lt;BR /&gt;
lookup file&lt;BR /&gt;
----------------&lt;BR /&gt;
id sal&lt;BR /&gt;
--  -----&lt;BR /&gt;
1  200&lt;BR /&gt;
1  300&lt;BR /&gt;
3  400&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I read file1 and need to use the lookup table and if id and sal is in lookup file then set id and sal to spaces in file1.Once id and sal are set to spaces I need to use logic to assign proper values to id and sal based on dept.&lt;BR /&gt;
once id and sal are spaces then logic to set id and sal are &lt;BR /&gt;
---------------------------------------------------------------------------------&lt;BR /&gt;
if dept = sales then id=s sal=250&lt;BR /&gt;
id dep = purchase then id=p sal=350&lt;BR /&gt;
&lt;BR /&gt;
if you can help me to fix this ,that would be really helpful&lt;BR /&gt;
&lt;BR /&gt;
Thanks all in advance.</description>
    <pubDate>Tue, 08 Jun 2010 17:27:46 GMT</pubDate>
    <dc:creator>ren2010</dc:creator>
    <dc:date>2010-06-08T17:27:46Z</dc:date>
    <item>
      <title>Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32832#M7952</link>
      <description>Hi All,&lt;BR /&gt;
Thanks to all for the valuable comments.This thread is more about the actual problem I  am facing.I am giving as example below.&lt;BR /&gt;
&lt;BR /&gt;
file1&lt;BR /&gt;
------&lt;BR /&gt;
id  sal  dept &lt;BR /&gt;
---  ---  ------&lt;BR /&gt;
1   200 sales&lt;BR /&gt;
2   300 purchase&lt;BR /&gt;
3   500 marketing&lt;BR /&gt;
&lt;BR /&gt;
lookup file&lt;BR /&gt;
----------------&lt;BR /&gt;
id sal&lt;BR /&gt;
--  -----&lt;BR /&gt;
1  200&lt;BR /&gt;
1  300&lt;BR /&gt;
3  400&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I read file1 and need to use the lookup table and if id and sal is in lookup file then set id and sal to spaces in file1.Once id and sal are set to spaces I need to use logic to assign proper values to id and sal based on dept.&lt;BR /&gt;
once id and sal are spaces then logic to set id and sal are &lt;BR /&gt;
---------------------------------------------------------------------------------&lt;BR /&gt;
if dept = sales then id=s sal=250&lt;BR /&gt;
id dep = purchase then id=p sal=350&lt;BR /&gt;
&lt;BR /&gt;
if you can help me to fix this ,that would be really helpful&lt;BR /&gt;
&lt;BR /&gt;
Thanks all in advance.</description>
      <pubDate>Tue, 08 Jun 2010 17:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32832#M7952</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-08T17:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32833#M7953</link>
      <description>I would think SQL would handle this.&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
create table file3 as select&lt;BR /&gt;
   case when dept = 'sales' and l.sal ne . then 's' &lt;BR /&gt;
           when dept = 'purchase' and l.sal ne . then 'p'&lt;BR /&gt;
           else a.id end as id,&lt;BR /&gt;
case when dept = 'sales' and l.sal ne . then 250 &lt;BR /&gt;
           when dept = 'purchase' and l.sal ne . then 350&lt;BR /&gt;
           else a.sal end as sal,&lt;BR /&gt;
dept from file1 a left join lookup l on a.id = l.id and a.sal = l.sal;&lt;BR /&gt;
&lt;BR /&gt;
(untested)</description>
      <pubDate>Tue, 08 Jun 2010 19:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32833#M7953</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-08T19:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32834#M7954</link>
      <description>I think you can directly overlap id and sal's values.&lt;BR /&gt;
For set id =p s , here id is character informat.&lt;BR /&gt;
and id,sal variates have been ordered by proc sort previously.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data file1;&lt;BR /&gt;
  input id $ sal dept $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200 sales&lt;BR /&gt;
2 300 purchase&lt;BR /&gt;
3 500 marketing&lt;BR /&gt;
;&lt;BR /&gt;
data lookup;&lt;BR /&gt;
  input id $ sal;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200&lt;BR /&gt;
1 300&lt;BR /&gt;
3 400&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp;&lt;BR /&gt;
  merge file1(in = in_file1) lookup(in = in_lookup);&lt;BR /&gt;
  by id sal;&lt;BR /&gt;
  if in_file1 and in_lookup then do;&lt;BR /&gt;
                    if dept='sales' then do;&lt;BR /&gt;
					            id='s'; sal=250;&lt;BR /&gt;
						 end;&lt;BR /&gt;
					else if dept='purchase' then do;&lt;BR /&gt;
					              id='p'; sal=350;&lt;BR /&gt;
						end;&lt;BR /&gt;
					 end;&lt;BR /&gt;
	if in_file1;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 09 Jun 2010 07:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32834#M7954</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-09T07:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32835#M7955</link>
      <description>Thanks Ksharp and Flip</description>
      <pubDate>Wed, 09 Jun 2010 19:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32835#M7955</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-09T19:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32836#M7956</link>
      <description>Now I have a different situation:&lt;BR /&gt;
&lt;BR /&gt;
data as;&lt;BR /&gt;
input id sal cd$ dept$ ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200 aa aa  &lt;BR /&gt;
2 300 bb ss &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data lookup;&lt;BR /&gt;
input id sal cd dept$;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200 3 aa&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
update as &lt;BR /&gt;
set dept=' ' where id in (select id from lookup) and sal in (select sal from lookup) and &lt;BR /&gt;
                  cd in (select cd from lookup) and dept in (select dept from lookup);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
In the next step i have to populate all DEPT who has missing values with the values of CD.&lt;BR /&gt;
&lt;BR /&gt;
In the above example after proc sql update the first record of file 'as' will look like:&lt;BR /&gt;
id sal  cd$ dept$ &lt;BR /&gt;
1  200 aa   &lt;BR /&gt;
&lt;BR /&gt;
and if I populate the missing dept with the value of aa again i make that row same as that of original ie 1 200 aa aa.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way I can check whether if the value of cd is in lookup  when I fix all DEPT with null values and if its present in lookup I populate with NODEPT value.&lt;BR /&gt;
&lt;BR /&gt;
Please let me know.&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Wed, 09 Jun 2010 19:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32836#M7956</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-09T19:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32837#M7957</link>
      <description>Hi. I don't think your sql will work because sal =3 in lookup ,however sal =aa in as.&lt;BR /&gt;
and i do not understand your mean totally.&lt;BR /&gt;
If you want output like ' 1 200 aa aa ' , you can use filp ' s suggestion such as 'case when...' .&lt;BR /&gt;
&lt;BR /&gt;
also can use  ' lookup.id ' in sql to check whether if the value of cd is in lookup......&lt;BR /&gt;
of course , data step can do it too.</description>
      <pubDate>Thu, 10 Jun 2010 07:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32837#M7957</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-10T07:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32838#M7958</link>
      <description>Thansk Ksharp,I corrected the data ,and also mentioned my desired output below:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data as;&lt;BR /&gt;
input id sal cd$ dept$ ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200 aa aa &lt;BR /&gt;
1 200 aa bb&lt;BR /&gt;
1 200 aa ee&lt;BR /&gt;
2 300 bb ss &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data lookup;&lt;BR /&gt;
input id sal cd$ dept$;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 200 aa aa &lt;BR /&gt;
1 200 aa ee&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
update as &lt;BR /&gt;
set dept=' ' where id in (select id from lookup) and sal in (select sal from lookup) and &lt;BR /&gt;
cd in (select cd from lookup) and dept in (select dept from lookup);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
In the next step i have to populate all DEPT who has missing values with the values of CD.&lt;BR /&gt;
&lt;BR /&gt;
In the above example after proc sql update the first record of file 'as' will look like:&lt;BR /&gt;
id sal cd$ dept$ &lt;BR /&gt;
1 200 aa &lt;BR /&gt;
&lt;BR /&gt;
and if I populate the missing dept with the value of aa again i make that row same as that of original ie 1 200 aa aa.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way I can check whether if the value of cd is in lookup when I fix all DEPT with null values and if its present in lookup I populate with NODEPT value.&lt;BR /&gt;
&lt;BR /&gt;
My desired output is like this:&lt;BR /&gt;
&lt;BR /&gt;
id sal cd$ dept$ ;&lt;BR /&gt;
1 200 aa NODEPT&lt;BR /&gt;
1 200 aa bb&lt;BR /&gt;
1 200 aa NODEPT&lt;BR /&gt;
2 300 bb ss &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Thu, 10 Jun 2010 16:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32838#M7958</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-10T16:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32839#M7959</link>
      <description>First back up and look at this line.&lt;BR /&gt;
"set dept=' ' where id in (select id from lookup) and sal in (select sal from lookup) "&lt;BR /&gt;
&lt;BR /&gt;
This looks to see if the ID is in the lookup, and then looks to see if the sal is in the lookup.  It DOES NOT look to see if the ID and SAL are associated.  &lt;BR /&gt;
SO id = 1, SAL = 300  Will match if 2 records exist such as ID = 1, SAL = 200 and ID = 3, SAL = 300&lt;BR /&gt;
&lt;BR /&gt;
Just add a case block for each condition and assign, there is no need to go through the data more than once.</description>
      <pubDate>Thu, 10 Jun 2010 17:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32839#M7959</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-10T17:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32840#M7960</link>
      <description>Hi. Flip is right. Your sql have some problem.&lt;BR /&gt;
try Flip's suggestion :  " case when lookup.id eq as.id and lookup.sal eq as.sal .....  then ' '   "      to check whether if the value of cd is in lookup when I fix all DEPT with null values.......</description>
      <pubDate>Fri, 11 Jun 2010 08:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32840#M7960</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-11T08:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32841#M7961</link>
      <description>Thanks Flip and Khsharp,&lt;BR /&gt;
&lt;BR /&gt;
The sql mentioned in my email is working fine.I did not see any issues when i ran it.It looks for the associated ID and SAL,not just an entry because I am using AND if had used OR then it would have picked any entry in the lookup table.&lt;BR /&gt;
&lt;BR /&gt;
Once I set the dept =' ' then in the next data step I have to fix the dept values like this:&lt;BR /&gt;
if dept=cd; and this time I wanted to check if the value of cd is in lookup table if the value of the cd is in lookup table then i make the dept=NODEPT.&lt;BR /&gt;
&lt;BR /&gt;
Thanks once again for your suggestions.</description>
      <pubDate>Fri, 11 Jun 2010 15:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32841#M7961</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-11T15:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32842#M7962</link>
      <description>Well, you can't say we didn't warn you. &lt;BR /&gt;
 It may work in your simple data, but the 2 exist clauses are not associated no matter if you use OR or AND.  Each exist looks to see if a record is in that table based on the one condition you have provided.

proc sql;&lt;BR /&gt;
update as a&lt;BR /&gt;
set dept='NO DEPT' where exists (select id from lookup l where a.id = l.id and a.sal = l.sal and a.cd = l.cd and a.dept = l.dept) ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Flip</description>
      <pubDate>Fri, 11 Jun 2010 16:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32842#M7962</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-11T16:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32843#M7963</link>
      <description>Hi. Your sql statement should not be error during compile stage.&lt;BR /&gt;
But the output should not be what you want as your said.&lt;BR /&gt;
Flip has some right suggestion.</description>
      <pubDate>Sat, 12 Jun 2010 07:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32843#M7963</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-12T07:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable and DATA step-Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32844#M7964</link>
      <description>Once Again Thank you to Ksharp and Flip.</description>
      <pubDate>Fri, 18 Jun 2010 22:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-variable-and-DATA-step-Part-2/m-p/32844#M7964</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-06-18T22:05:50Z</dc:date>
    </item>
  </channel>
</rss>

