Hello,
I am new to SAS. I am trying to write the below SQL script in SAS and wrap in Proc SQL
FinalStatus = CAST(SUBSTRING(MAX(CAST(cl.DateNotesEntered AS BINARY(6)) + CAST(cl.CallResult AS VARBINARY(1000))), 7, 1000) AS VARCHAR(1000)),
Any help on how this statement would be written in Proc SQL for SAS
CAST isn't a SAS function, you would use PUT instead.
What type of SQL is that?
I though the variable name was always at the end?
This may be easier if you show what you have and what you need, there may be other ways in SAS that are more efficient?
yes you are right the variable name is normally at the end but you can also put it in the beginning. the SQL code above was writen in SQL server.
Basically what the line of sql is giving the max status for the max date
so for example, below i would want to return the max status which is the record with the greatest date.
Max status would be Completed.
A Date Status
Example 1/1/2017 Open
Example 1/3/2017 Pending
Example 1/4/2017 Completed
Do you have to use SQL?
A Data Step does this very easily.
proc sort data=have;
by a date;
run;
data want;
set have;
by a date;
if last.a; *takes the last record of each A group;
run;
Yes i would prefer sql since i have a entire statement i am running to create a table.
I think you'll have to do a subquery and join then, I don't think this will translate into SAS code directly.
@Reggiete I'm not sure if I understood your req as I am wondering what is the big deal in proc sql. Please let me know if i'm missing something:
data have;
input A : $10. Date :mmddyy10. Status $; /*assuming the date is mmddyy10.*/
format date mmddyy10.;
datalines;
Example 1/1/2017 Open
Example 1/3/2017 Pending
Example 1/4/2017 Completed
;
proc sql;
create table want as
select *
from have
group by a
having date=max(date);
quit;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: