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

The following code produces a 22-322 and a 76-322 syntax error:

 

proc sql;
	create table InstallDate as
		SELECT
			FLT.vehicle_header,
			FLT.vehicle_no,
			FLT.occur_date,
			FLT.FAULT_CODE,
			FLT.FAULT_DESCRIPTION
		FROM RMDEOAP.GETS_DW_EOA_FAULTS FLT
			WHERE 
			FLT.vehicle_header = 'NS'
			/*and FLT.occur_date between '25Sep2016:00:00:00'dt and datetime()*/
			and FLT.occur_date between '25Jul2017:00:00:00'dt and datetime()
	;
quit;
data InstallDate;
set InstallDate;
select min( occur_date) as sw_install_date
group by vehicle_no
;
run;

The error message appears following the statement:

 

select min( occur_date) as sw_install_date

 

I'm trying to find the minimum occur_date grouped by vehicle number. 

 

Thanks and best regards.

capam

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You only need a single query:

 

proc sql;
create table InstallDate as
SELECT
	FLT.vehicle_header,
	FLT.vehicle_no,
	FLT.occur_date,
	FLT.FAULT_CODE,
	FLT.FAULT_DESCRIPTION,
	min(FLT.occur_date) as sw_install_date
FROM RMDEOAP.GETS_DW_EOA_FAULTS FLT
WHERE 
	FLT.vehicle_header = 'NS' and
	FLT.occur_date between '25Jul2017:00:00:00'dt and datetime()
group by FLT.vehicle_no;
quit;
PG

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20
Your first SQL looks fine. But why do you switch to a data step (and mix with SQL syntax - which isn't supported)?
Data never sleeps
PGStats
Opal | Level 21

You only need a single query:

 

proc sql;
create table InstallDate as
SELECT
	FLT.vehicle_header,
	FLT.vehicle_no,
	FLT.occur_date,
	FLT.FAULT_CODE,
	FLT.FAULT_DESCRIPTION,
	min(FLT.occur_date) as sw_install_date
FROM RMDEOAP.GETS_DW_EOA_FAULTS FLT
WHERE 
	FLT.vehicle_header = 'NS' and
	FLT.occur_date between '25Jul2017:00:00:00'dt and datetime()
group by FLT.vehicle_no;
quit;
PG
capam
Pyrite | Level 9

Hi PGStats

I tried your suggestion and got the following error:

17 proc sql;
18 create table InstallDate as
19 SELECT
20 FLT.vehicle_header,
21 FLT.vehicle_no,
22 FLT.occur_date,
23 FLT.FAULT_CODE,
24 FLT.FAULT_DESCRIPTION
25 min(FLT.occur_date) as sw_install_date
26 FROM RMDEOAP.GETS_DW_EOA_FAULTS FLT
27 WHERE
28 FLT.vehicle_header = 'NS' and
29 FLT.occur_date between '25Jul2017:00:00:00'dt and datetime()
30 group by FLT.vehicle_no
31 ;
ERROR: Expression using minimum of (><) has components that are of different data types.
WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING
clause of the associated table-expression referenced a summary function.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
32 quit;
NOTE: The SAS System stopped processing this step because of errors.

 

Thanks for your quick response.

capam

capam
Pyrite | Level 9
Sorry, I forgot a comma after line 24 above. Thanks for the help.

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!

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.

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
  • 4 replies
  • 1032 views
  • 0 likes
  • 3 in conversation