BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello i have 2 tables. Table X has EMAIL and DATE and table Y has EMAIL, DATE, and SALES. i want to pull all sales for the previous year from Y for emails based on a day before their DATE in X. so the date range in Y will be constantly changing by EMAIL based on X.DATE. I need to use sql code to access the server.

so the date part of the query would be
y.date between x.date-366 and x.date-1

can somebody tell me how to do this?
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You have the INTNX function available to use with PROC SQL and have you considered defining a nested query?

Also, do you have any code-attempts you have made on this request so far, which you can share and receive excellent input/feedback?

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
> Hello i have 2 tables. Table X has EMAIL and DATE
> and table Y has EMAIL, DATE, and SALES. i want to
> pull all sales for the previous year from Y for
> emails based on a day before their DATE in X. so the
> date range in Y will be constantly changing by EMAIL
> based on X.DATE. I need to use sql code to access
> the server.
>
> so the date part of the query would be
> y.date between x.date-366 and x.date-1
>
> can somebody tell me how to do this?


>
> can somebody tell me how to do this?

I'm sure "someone" can, but ...

since you want to run sql on the server, it might help to :
1
consider which server or server-type will run your code
2
consider telling us what server
3
consider using a forum that deals with that database server

good as poster/answerers on this forum generally are, mind reading is normally not available
Patrick
Opal | Level 21
In order to give you working SQL code you would have to provide us with sample data (2 data steps creating table X and Y).

Even better would be to then also give the expected result set based on the sample data sets.

The SQL code can be written in SAS SQL, SAS then translates it into DB specific SQL (this works even with certain data step commands like modify).

The minimum needed is to know which variables make up a unique key in the 2 tables and what the relationship between the tables is (1:1, 1:many,...).

HTH
Patrick

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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