<?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: Convert Sybase Procedure to SAS in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33821#M8205</link>
    <description>From your explanation, possibly a program-flow sequence using multiple sorts (one to filter update candidates; another to de-dup'ing to get one obs with min value from to data-matching table2), merge, with output to a tracking file for identifying deletions in the same DATA step as the MERGE (capture some key variables or _N_ obs # in table 2 for deletion candidate).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 19 May 2009 21:14:37 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-05-19T21:14:37Z</dc:date>
    <item>
      <title>Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33816#M8200</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I need some help in converting a Sybase procedure to SAS. I understand Oracle Procedures but new to Sybase.&lt;BR /&gt;
&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
&lt;BR /&gt;
DECLARE alloc_crsr CURSOR FOR&lt;BR /&gt;
SELECT distinct &lt;BR /&gt;
    i.id,&lt;BR /&gt;
    i.help_par,&lt;BR /&gt;
    i.id_pig,&lt;BR /&gt;
    i.cd_intent,&lt;BR /&gt;
    i.id_ramesh&lt;BR /&gt;
FROM $WRK..help_list i&lt;BR /&gt;
order by i.id&lt;BR /&gt;
FOR READ ONLY&lt;BR /&gt;
go&lt;BR /&gt;
&lt;BR /&gt;
set nocount on&lt;BR /&gt;
DECLARE &lt;BR /&gt;
    @id_pig varchar(10), &lt;BR /&gt;
    @pig_seq varchar(10),&lt;BR /&gt;
    @id varchar(10),&lt;BR /&gt;
    @id_ramesh varchar(8),&lt;BR /&gt;
    @cd_intent char(1),&lt;BR /&gt;
    @amt_par float,&lt;BR /&gt;
    @split_pct float,&lt;BR /&gt;
    @help_allocated char(1),&lt;BR /&gt;
    @prev_id varchar(10)&lt;BR /&gt;
&lt;BR /&gt;
SELECT @help_allocated = 'N'&lt;BR /&gt;
SELECT @prev_id = '0'    &lt;BR /&gt;
&lt;BR /&gt;
OPEN pigs_alloc_crsr&lt;BR /&gt;
FETCH pigs_alloc_crsr INTO  @id, @amt_par, @id_pig, @cd_intent, @id_ramesh&lt;BR /&gt;
WHILE (@@sqlstatus = 0)&lt;BR /&gt;
BEGIN&lt;BR /&gt;
&lt;BR /&gt;
    IF @prev_id != @id&lt;BR /&gt;
    BEGIN&lt;BR /&gt;
        SELECT @help_allocated = 'N'&lt;BR /&gt;
        SELECT @prev_id = @id&lt;BR /&gt;
    END&lt;BR /&gt;
&lt;BR /&gt;
    IF @help_allocated = 'N'&lt;BR /&gt;
    BEGIN&lt;BR /&gt;
        SELECT @pig_seq = min(l.pig_seq)&lt;BR /&gt;
        FROM $WRK..pig_list l&lt;BR /&gt;
        WHERE l.pig_par = @amt_par&lt;BR /&gt;
        and l.id_pig = @id_pig&lt;BR /&gt;
        and l.cd_intent = @cd_intent&lt;BR /&gt;
        and l.id_ramesh = @id_ramesh&lt;BR /&gt;
&lt;BR /&gt;
        IF @pig_seq is not null&lt;BR /&gt;
        BEGIN&lt;BR /&gt;
            SELECT @help_allocated = 'Y'&lt;BR /&gt;
&lt;BR /&gt;
            SELECT @split_pct = split_pct&lt;BR /&gt;
            FROM $WRK..pig_list &lt;BR /&gt;
            WHERE id_pig = @id_pig&lt;BR /&gt;
            AND pig_seq = @pig_seq&lt;BR /&gt;
            AND pig_par = @amt_par&lt;BR /&gt;
            AND cd_intent = @cd_intent&lt;BR /&gt;
            and id_ramesh = @id_ramesh&lt;BR /&gt;
&lt;BR /&gt;
            INSERT INTO $WRK..final_conv_$TAG&lt;BR /&gt;
            SELECT&lt;BR /&gt;
                @id,&lt;BR /&gt;
                @amt_par,&lt;BR /&gt;
                @id_pig,&lt;BR /&gt;
                @id_ramesh,&lt;BR /&gt;
                @cd_intent,&lt;BR /&gt;
		@pig_seq,&lt;BR /&gt;
		@amt_par,&lt;BR /&gt;
		@split_pct,&lt;BR /&gt;
		1,&lt;BR /&gt;
		'1-1 pig_mtch'&lt;BR /&gt;
&lt;BR /&gt;
	    DELETE $WRK..pig_list&lt;BR /&gt;
	    WHERE id_pig = @id_pig&lt;BR /&gt;
	    AND pig_seq = @pig_seq&lt;BR /&gt;
	    AND cd_intent = @cd_intent&lt;BR /&gt;
	    AND id_ramesh = @id_ramesh&lt;BR /&gt;
        END&lt;BR /&gt;
    END&lt;BR /&gt;
&lt;BR /&gt;
    COMMIT &lt;BR /&gt;
&lt;BR /&gt;
    FETCH pigs_alloc_crsr INTO  @id, @amt_par, @id_pig, @cd_intent, @id_ramesh&lt;BR /&gt;
END&lt;BR /&gt;
go&lt;BR /&gt;
&lt;BR /&gt;
CLOSE pigs_alloc_crsr        &lt;BR /&gt;
go&lt;BR /&gt;
&lt;BR /&gt;
DEALLOCATE CURSOR pigs_alloc_crsr&lt;BR /&gt;
go&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;/CODE&gt;&lt;/CODE&gt;</description>
      <pubDate>Tue, 19 May 2009 16:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33816#M8200</guid>
      <dc:creator>w020637</dc:creator>
      <dc:date>2009-05-19T16:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33817#M8201</link>
      <description>Just curious if you even attempted to crack the Sybase documentation at all, or are you expecting individuals on the SAS discussion forum to help decode the SYBASE as well as write your SAS program?  &lt;BR /&gt;
&lt;BR /&gt;
It would appear useful to at least attempt on your part to associate some "logic flow" processing comments with the SYBASE program/script while understanding the desired input (source data) and output (SAS data and any reports/graphics), from which a SAS program can be constructed.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 19 May 2009 17:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33817#M8201</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-19T17:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33818#M8202</link>
      <description>Thanks Scott,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to decode this Sybase procedure. I understand what the procedure is doing but there are issues with converting the functionality to SAS.&lt;BR /&gt;
&lt;BR /&gt;
Here is the process flow:&lt;BR /&gt;
&lt;BR /&gt;
1.  There 3 tables which I can get into a dataset.&lt;BR /&gt;
2.   Basically we loop through each record in table 1 (help_list) and find the minimum pig_seq from table2 (pig_list).&lt;BR /&gt;
3.  Then get the split_pct from that table2 (pig_list) for that particlaur record minimum pig_seq. &lt;BR /&gt;
4. Store the variables from table1 and table2 in table3.&lt;BR /&gt;
5. delete the particulr record i.e. minimum pig_seq. from table2 (pig_list).&lt;BR /&gt;
&lt;BR /&gt;
The challenge in to get the minimum pig_seq from table2.&lt;BR /&gt;
&lt;BR /&gt;
Regards</description>
      <pubDate>Tue, 19 May 2009 17:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33818#M8202</guid>
      <dc:creator>w020637</dc:creator>
      <dc:date>2009-05-19T17:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33819#M8203</link>
      <description>Scott,&lt;BR /&gt;
&lt;BR /&gt;
As I had previously mentioned that I was working on a solution.&lt;BR /&gt;
&lt;BR /&gt;
Here is the solution:&lt;BR /&gt;
 &lt;BR /&gt;
1. Sort table 1 on which the join has to be made.&lt;BR /&gt;
pig_par  id_pig  cd_intent id_ramesh(key) in ascending&lt;BR /&gt;
&lt;BR /&gt;
2. Sort table 2 on &lt;BR /&gt;
&lt;BR /&gt;
pig_par  id_pig  cd_intent id_ramesh(key) in ascending and pig_seq in descending.&lt;BR /&gt;
&lt;BR /&gt;
3. Merge the two tables by key.&lt;BR /&gt;
&lt;BR /&gt;
data combine;&lt;BR /&gt;
merge table1(in=a) table2(in=b);&lt;BR /&gt;
by key;&lt;BR /&gt;
if A;&lt;BR /&gt;
if first.id_ramesh then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 19 May 2009 17:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33819#M8203</guid>
      <dc:creator>w020637</dc:creator>
      <dc:date>2009-05-19T17:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33820#M8204</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
This is not working and so please ignore the suggested approach. Accept my apologies.&lt;BR /&gt;
&lt;BR /&gt;
Here is modified process flow still dont know how to convert to sas.&lt;BR /&gt;
&lt;BR /&gt;
1. There 3 tables which I can get into a dataset.&lt;BR /&gt;
2. Table 1 has unique records as far as id,help_par,id_pig,cd_intent,id_ramesh is concerned. A particular id should be processed just once. &lt;BR /&gt;
That is the reason we have two variables&lt;BR /&gt;
help_allocated = 'N'&lt;BR /&gt;
prev_id = '0' &lt;BR /&gt;
to keep track of it.&lt;BR /&gt;
2. We loop through each record in table 1 (help_list) and find the minimum pig_seq from table2 (pig_list) only if the help_allocated = 'N' for that particlaur id.&lt;BR /&gt;
If a match is found do step3&lt;BR /&gt;
3. Then get the split_pct from that table2 (pig_list) for that particlaur record minimum pig_seq. &lt;BR /&gt;
4. Store the variables from table1 and table2 in table3.&lt;BR /&gt;
5. delete the particulr record i.e. minimum pig_seq. record from table2 (pig_list).This is a bit tricky as you have to delete the record from a dataset&lt;BR /&gt;
which is being used in the process(here it is merge).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The challenge is illustrated in the example below:&lt;BR /&gt;
&lt;BR /&gt;
id,help_par,id_pig,cd_intent,id_ramesh  		help_par,id_pig,cd_intent,id_ramesh ,pig_seq&lt;BR /&gt;
1   A        B        C        D 			   A        B        C        D       1&lt;BR /&gt;
1   X        Y        Z        W 			   A        B        C        D       2&lt;BR /&gt;
2   A        B        C        D 			   X        Y        Z        W       1&lt;BR /&gt;
2   X        Y        Z        W 			   A        B        C        D       1&lt;BR /&gt;
3   A        B        C        D 			   A        B        C        D       1&lt;BR /&gt;
&lt;BR /&gt;
Suppose this is the dataset. The output(table3) should be&lt;BR /&gt;
&lt;BR /&gt;
id,help_par,id_pig,cd_intent,id_ramesh  		help_par,id_pig,cd_intent,id_ramesh ,pig_seq&lt;BR /&gt;
1   A        B        C        D 			   A        B        C        D       1&lt;BR /&gt;
1   X        Y        Z        W 			   &lt;BR /&gt;
2   A        B        C        D                           A        B        C        D       2			   &lt;BR /&gt;
2   X        Y        Z        W 			   &lt;BR /&gt;
3   A        B        C        D 			   A        B        C        D       1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
After deltion the final pig_list should have the following records.&lt;BR /&gt;
&lt;BR /&gt;
X        Y        Z        W       1&lt;BR /&gt;
A        B        C        D       1&lt;BR /&gt;
&lt;BR /&gt;
Regards</description>
      <pubDate>Tue, 19 May 2009 20:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33820#M8204</guid>
      <dc:creator>w020637</dc:creator>
      <dc:date>2009-05-19T20:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Sybase Procedure to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33821#M8205</link>
      <description>From your explanation, possibly a program-flow sequence using multiple sorts (one to filter update candidates; another to de-dup'ing to get one obs with min value from to data-matching table2), merge, with output to a tracking file for identifying deletions in the same DATA step as the MERGE (capture some key variables or _N_ obs # in table 2 for deletion candidate).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 19 May 2009 21:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-Sybase-Procedure-to-SAS/m-p/33821#M8205</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-19T21:14:37Z</dc:date>
    </item>
  </channel>
</rss>

