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

Hello all

 

I have inherited SAS code that has approx. 20 steps and the code had errors throughout. I have been successful in cleaning it up until the last two steps. This is the code for the first one 

PROC SQL;
CREATE TABLE WORK.AllClaims1 (DROP= Discharge Date Rename= (Discharge Date1= Discharge Date)) AS 
SELECT *
 ,INPUT(Discharge Date,5.) - 21916 AS Discharge Date1 FORMAT= mmddyy10.
FROM WORK.AllClaims
;QUIT;

This is the error message I get:

22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, ?, AND, CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.

The is the code for the other step 

DATA AllClaims_Updated;
SET hphc_EOL_FY20 WORK.AllClaims;
RUN;

This the error message that I get:

ERROR: Variable Age has been defined as both character and numeric.
ERROR: Variable BMT has been defined as both character and numeric.

These are the two columns that are effected and their types.

work.EOL_COHORT Age = Type Numeric, Length 8
BHM = Type Character, Length Character 1

AllCohorts1 Age = Type Character, Length Character 1
BHM = Type Numeric, Length 8

 Any assistance with these would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
wheddingsjr
Pyrite | Level 9

Thanks all for your responses. The imported source document (excel), had a space between the heading "Discharge Date", that's why I wanted to do the rename. Instead I used a "_" between the two words and commented out the rename step, and it worked perfectly.

View solution in original post

7 REPLIES 7
wheddingsjr
Pyrite | Level 9

My apologies, this did not present the way I typed it so I am going to attach the code and errors in a word document

RogerHed
Obsidian | Level 7

The Sql:

  1. In the Rename there is a Date=, remove the "=".
  2. The Format "Date,5." I suppose is meant to be "date5.".

The Data step:

You have to decide if what type AGE and BMT must be if the two datasets are to be appended. A couple of choices:

  • I they mean the same thing, change into numeric or character in both datasets before appending. You can use a SQL View to do that before the datastep on the input ataset you want to alter into the append Data step.
  • If they mean different and are to be kept separate in the appended output, add a rename on one of the input datasets. 
wheddingsjr
Pyrite | Level 9

Thanks RogerHed. The AGE should be Type = Numeric, length = 8 and the BMT should be Type = Character, Length = 1 in both datasets.Unfortunately, as a novice I searched the internet to learn how to do that but I was unsuccessful in finding the proper way to include that logic.

RogerHed
Obsidian | Level 7
No sorry, the Rename is confusing "Discharge Date1= Discharge Date"
Column name must come in pairs like x=y z=q.
Do you want to rename Discharge to Date1?
Kurt_Bremser
Super User

Do not type code and logs manually; just copy/paste the text as is into the appropriate codeboxes.

 

What immediately catches my attention is the fact that there seem to be blanks in variable names. This is not correct syntax.

If you actually have blanks in variable names, you need to use so-called "name literals":

"Discharge Date"n

The spelling must be correct with regards to upper/lowercase. It is STRONGLY recommended to avoid this, so rename those variables immediately to valid SAS names (use underlines in place of blanks).

TomKari
Onyx | Level 15

It looks to me like your first step (the PROC SQL) would work, except for one thing.

 

There are a number of uses of "Discharge Date", with a space between the two words. If this was a proper SAS variable, I think the code would work fine.

 

You say this is inherited code. As it is, there is no way this code will work. It looks to me like something happened to change a correct variable, possible "DischargeDate" or "Discharge_Date", to "Discharge Date". Has anything like that happened, and have any other changes been made?

 

You're probably best leaving the later steps until the earlier problems get solved. Problems tend to cascade.

 

Tom

wheddingsjr
Pyrite | Level 9

Thanks all for your responses. The imported source document (excel), had a space between the heading "Discharge Date", that's why I wanted to do the rename. Instead I used a "_" between the two words and commented out the rename step, and it worked perfectly.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1844 views
  • 0 likes
  • 4 in conversation