Questions tagged [proc-sql]

proc sql is a SAS procedure used to submit SQL statements to the SAS compiler. For Oracle Pro*C, please use [oracle-pro-c].

proc sql; is a SAS procedure used to submit SQL statements to the SAS compiler. It is optionally terminated by a quit; statement. An example of typical syntax would be:

proc sql;
create table z as
  select * 
  from x
  left join y
  on x.id=y.id
  order by 1,2,3;
quit;

A more 'SAS specific' example would be the direct creation of macro variables, such as:

proc sql noprint; 
select someVariable into: MyMacroArray separated by ' ' 
  from work.Input where varCondition='True';

For further details on syntax, click here (v9.4) or here (v9.3)

794 questions
3
votes
4 answers

SAS explicit pass-through with --comments converts to single line

It appears that when performing an explicit pass-through with SAS, the text is not delivered to the server in the same manner that it is laid out within the editor or .sas file itself. SAS appears to be delivering the text all on a single line. This…
Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
3
votes
2 answers

SAS PROC SQL: How to clear cache between testing

I am reading this paper: "Need for Speed - Boost Performance in Data Processing with SAS/Access® Interface to Oracle". And I would like to know how to clear the cache / buffer in SAS, so my repeated query / test will be reflective of the changes…
George
  • 4,514
  • 17
  • 54
  • 81
3
votes
2 answers

Using proc sql, Where at least 1 column is a value

How do i write in sas: proc sql; create table THIS as select * from MAIN(keep=id col1 -- col34) where (AT LEAST ONE OF THE COLUMNS contains 1) ; ; I am having a problem figuring out how to write that last line bc I want…
Jessica Warren
  • 378
  • 1
  • 4
  • 15
3
votes
2 answers

Proc sql subquery based on nonexisitng column returns not null

Here is a sample code that was derived from actual application. There are two datasets - "aa" for a query and "bb" for subquery. Column "m" from datasets "aa" matches column "y" from datasets "bb". Also, there is "yy" column on "aa" table has a…
3
votes
1 answer

Error Handling in a sas macro

I am writing a simple macro to count distinct values in all the columns of a table. I need to include an error handler which displays an error information and conitnues to execute the macro further, if certain column is found in the first but not…
ch1nmay
  • 81
  • 1
  • 7
3
votes
3 answers

proc sql outobs= triggers SAS warning

We currently use the %runquit macro function as detailed here (http://analytics.ncsu.edu/sesug/2010/CC07.Blanchette.pdf). The %runquit macro is shown below. It basically stops running any more SAS code when an error is encounterd, and can be used…
Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
3
votes
1 answer

SAS: How to copy a local sas table into oracle via SQL pass-through

After making some searches that didn't lead to anything useful for me, I would like to ask you this question. Some background: I would like to create an oracle table via two different methods in order to compare performances. Actually I want to copy…
martinlegrand
  • 33
  • 1
  • 5
3
votes
1 answer

How do I convert a number column like 200012 to a SAS date variable using PROC SQL?

I have a SAS data set with a text field customer_id and a numeric field month in the format YYYYMM. I'm creating a view of these data, and I want to convert the data to a standard SAS date that will (hopefully) be preserved on export. For…
Michael A
  • 4,391
  • 8
  • 34
  • 61
3
votes
1 answer

Proc SQL output not showing

The my knowledge using Proc SQL should allow you to bypass the PRINT procedure and print the output automatically, but for some reason the output is not showing up. My output destination is active, and my log has no errors. This is my code. proc…
user3642531
  • 309
  • 4
  • 12
3
votes
5 answers

SAS datastep/SQL select latest record from multiple records with same ID

For example I have a dataset as below: id Date 1 2000/01/01 1 2001/01/01 1 2002/01/01 2 2003/01/01 By datastep or sql, how could I get the record with id = 1 and latest Date 2002/01/01? Help is appreciated and thanks in advance.
Luke Henz
  • 137
  • 3
  • 5
  • 12
3
votes
3 answers

SAS proc sql to turn 2 columns into 1 column

Suppose I have a table A | B =============== Dan | Jack April | Lois Matt | Davie Andrew | Sally and I want to make a table C ====== Dan April Matt Andrew Jack Lois Davie Sally using SAS proc sql. How can I do that?
synaptik
  • 8,971
  • 16
  • 71
  • 98
3
votes
3 answers

SAS: Selecting frequency of multi-column value

I have this problem, but in SAS. To use the example provided in this question, I have 5 columns of names (name_1, name_2, etc.), and want to output a list in which the names are listed in descending order of frequency: John 502 Robert …
David C
  • 7,204
  • 5
  • 46
  • 65
2
votes
1 answer

SAS proc import missing leading zero

I am trying to import numbers from csv file to sas dataset with proc import ( SAS ) , but all my leading zero are disappear after the import. For example, '0123456' after import I would get only '123456'
JPC
  • 5,063
  • 20
  • 71
  • 100
2
votes
2 answers

Need help finding overlapping dates between two tables and creating a Y/N flag in SAS

I have 2 datasets that I am working on which have a few overlapping dates. I want to create a flag which will check each 'date_lab' date for each id in TABLE B and cross reference it with the the start and end date ranges in TABLE A. If there is an…
Sana
  • 23
  • 3
2
votes
1 answer

Optimize proc sql statements in SAS

I'm very new to SAS and trying to learn it. I have a problem statement where I need to extract two files from a location and then perform joins. Below is a detailed explanation of what I'm trying to achieve in a single proc sql statement: There are…
hk2
  • 487
  • 3
  • 15
1 2
3
52 53