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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1303 views
  • 0 likes
  • 3 in conversation