BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

Hi ,

Could some one help me with the equivalent SQL code ???

this code in basic SAS is mainly merges and a couple of transposes

thanks

Hi,

Thanks for your inputs.

I want to take back my question

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

What precisely do you want help on as I am not writing all that code.  Also, why do you need to convert it to SQL, is it to move it to a database, if so then you need to investigate the database syntax as they have additional functionality which will help.  The only thing at a quick glance that I would suggest being difficult is the transpose as SQL is built to work on normalized tables rather than transposed.

One final thing.  You may be quicker looking at your final datastep and working back from there e.g.

data final(drop=     /* This becomes proc sql; create table final as

set location; /* move to end */

/* These are your select statements */

SEX=input(put(gender_name,$sex.),3.);

RACE=input(put(Ethnic_Group,$race.),3.);

PAY1=input(put(Financial_Class,$payer.),3.);

HOSPID=input(put(Company_Code,$hosp.),4.);

DRG=MSDRG_CODE*1;

POINTOFORIGINUBO4=put(Admit_Source_Code,$Porign.);

MDC=input(put(DRG,MDC.),best.);

/* change to case statemtn */ if MSDRG_code="N/C" then MSDRG_code="000";

/* add in here locations for each of the above variables */

/* and join them */

run;

Note you can drop all the sort statements as SQL doesn't require pre-sorted data like SAS.  Depending on your platform, the formats will only work in SAS.  My choice is to remove that and put your formats in another dataset and use that as lookup e.g.

(select THIS.CODE_VALUE from CODE_DATASET THIS where THIS.CODE=BASE.CODE) as LONG_VALUE,

One final thing, you use arrays at a point in your table, you would need to re-think your logic there as (I mentioned before) SQL is based on normalized (or data going down rather than across) tables.  So you may struggle to get the data going across, or have the functionality to process data across.

Take it bit by bit also

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

What precisely do you want help on as I am not writing all that code.  Also, why do you need to convert it to SQL, is it to move it to a database, if so then you need to investigate the database syntax as they have additional functionality which will help.  The only thing at a quick glance that I would suggest being difficult is the transpose as SQL is built to work on normalized tables rather than transposed.

One final thing.  You may be quicker looking at your final datastep and working back from there e.g.

data final(drop=     /* This becomes proc sql; create table final as

set location; /* move to end */

/* These are your select statements */

SEX=input(put(gender_name,$sex.),3.);

RACE=input(put(Ethnic_Group,$race.),3.);

PAY1=input(put(Financial_Class,$payer.),3.);

HOSPID=input(put(Company_Code,$hosp.),4.);

DRG=MSDRG_CODE*1;

POINTOFORIGINUBO4=put(Admit_Source_Code,$Porign.);

MDC=input(put(DRG,MDC.),best.);

/* change to case statemtn */ if MSDRG_code="N/C" then MSDRG_code="000";

/* add in here locations for each of the above variables */

/* and join them */

run;

Note you can drop all the sort statements as SQL doesn't require pre-sorted data like SAS.  Depending on your platform, the formats will only work in SAS.  My choice is to remove that and put your formats in another dataset and use that as lookup e.g.

(select THIS.CODE_VALUE from CODE_DATASET THIS where THIS.CODE=BASE.CODE) as LONG_VALUE,

One final thing, you use arrays at a point in your table, you would need to re-think your logic there as (I mentioned before) SQL is based on normalized (or data going down rather than across) tables.  So you may struggle to get the data going across, or have the functionality to process data across.

Take it bit by bit also

Patrick
Opal | Level 21

I believe you need to ask a bit more educated and targeted questions. You can't really expect anyone to just do all the work for you.

You would also need to explain why this needs to be done using SQL.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 722 views
  • 0 likes
  • 3 in conversation