SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
rahulsaha2127
Fluorite | Level 6

I have the following code which I need to convert in SAS form: 

 

create volatile table gl as (
select GEN_ID, AU_GEN_ID, TYPE_2_DESC,
TYPE_5_DESC, TYPE_8_DESC
from COMMERCIAL_V3.DATA_F
qualify row_number() over
(partition by , GEN_ID, AU_GEN_ID order by DATA_OUTSTANDING_AMT desc,
DATA_TOTAL_COMMITMENT_AMT desc, DATA_GEN_ID desc)=1
) with data on commit preserve rows;

 

Please share your inputs. TIA.

4 REPLIES 4
LinusH
Tourmaline | Level 20

S lets's break into parts:

- volatile table: it's equivalent to store a table (SAS dataset) in the WORK library.

- row_number: in SAS PROC SQL there's an undocumented (hence not supported) function monotonic(). If you need to keep track on row numbers using supported functionality you need to use the data step instead of SQL (automatic _n_ variable).

- qualify / partition by: can you explain what this does? I know about window functions but haven't really used them? Perhaps you need to attach an example of "have" data and what't the output.

Data never sleeps
s_lassen
Meteorite | Level 14

The QUALIFY statement means that we are only taking the first row from each group. I think the easiest way to do this is to take all the data out in the order we want it, and then use a data step to get the first row in each partition:

proc sql;
create table temp as
select GEN_ID, AU_GEN_ID, TYPE_2_DESC,
TYPE_5_DESC, TYPE_8_DESC,  DATA_OUTSTANDING_AMT, 
DATA_TOTAL_COMMITMENT_AMT
from COMMERCIAL_V3.DATA_F
order by GEN_ID, AU_GEN_ID, DATA_OUTSTANDING_AMT desc,
DATA_TOTAL_COMMITMENT_AMT desc, DATA_GEN_ID desc;
quit;

data want;
  set temp;
  by GEN_ID AU_GEN_ID;
  if first.AU_GEN_ID;
  drop DATA_OUTSTANDING_AMT DATA_TOTAL_COMMITMENT_AMT;
run;

This assumes that your input data has been moved to a SAS library. If it is still in Teradata, you may be better off using SQL passthrough to Teradata.

Ksharp
Super User
/*
You'd better post a INPUT dataset and a OUTPUT dataset
to explain what you are looking for.
If I was right,try this code:
*/
proc sort data=have out=temp;
by 
 GEN_ID
 AU_GEN_ID 
 descending DATA_OUTSTANDING_AMT 
 descending DATA_TOTAL_COMMITMENT_AMT 
 descending DATA_GEN_ID 
;
run;
proc sort data=temp out=want nodupkey;
by 
 GEN_ID
 AU_GEN_ID 
;
run;
SASKiwi
PROC Star

It's not clear what your actual use case is here. What data source will you be working with once you convert the Teradata code. Will it still be Teradata or will your data source change to SAS as well? If you continue to use Teradata as your data source then there is no need to rewrite your Teradata code. Just wrap it in a SAS SQL Passthru step and run it unchanged.  

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1478 views
  • 1 like
  • 5 in conversation