hi there,
i run a query in MS SQL where the query selects all records from 4 tables and unions them. Result set is then 249236 records
I copied the same code in SAS and placed it in the PROC SQL command yet i get 286966 records. This is a difference of 37736 records and the code is the exact same. Do you know why?
Can you post the code for each including the LIBNAME statements?
I dont think i understand as i connect directly to SQL server from SAS
To @Reeza's point, there is always a Lib in SAS. If it's not coded, then it's WORK by default.
For your SAS code, can you post everything from the PROC SQL to the QUIT?
For your SQL server code, can you post actual code?
Jim
I'm sorry but i do not get what you are saying. Please elaborate
There are lots of options for what could be going wrong.
I would recommend you make a small test query which replicates the problem, and is something you would be able to share.
You might also check the counts you get from just select * from both tables, and make sure those match.
Finally, UNION will (by default) return distinct values. You might change to UNION ALL and see if they will match. I don't know MS SQL server that well, I suppose it's possible to set a SQL server database as case-insensitive, which could lead to SQL server treating more values as duplicates than SAS would.
Simplify your problem by doing row counts on single tables in SQL Server and in SAS then compare results.
Identify which tables show a different row counts - all or just some?
hi thank you for the suggestions. i did a ccomparison and i see that the time is pulling with the date, thus there are multiple records.
How do i get only the date from a datetime SQL column?
@Citrine10 wrote:
hi thank you for the suggestions. i did a ccomparison and i see that the time is pulling with the date, thus there are multiple records.
How do i get only the date from a datetime SQL column?
I am not sure why MS-SQL would consider two different datetime values as being the same just because they occur on the same date, but in SAS code you can use the DATEPART() function to convert a datetime value (number of seconds) into a date value (number of days). Make sure to change the format attached since displaying a date value as if it was a datetime value will make all reasonable dates look like they are some time early in the morning of 01JAN1960.
You can also change all the datetime values to the datetime value for the start of the day by using the INTNX() function with the DTDATE interval.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.