proc-sql

SAS: Run SQL-query using a macro

会有一股神秘感。 提交于 2020-04-30 06:31:28
问题 Using an answer from this thread, I was trying to get to work the following code. I have a list of sql-queries in a table plus an id for each query. Now I'd like to have the results of these queries plus the id as another table. /* The Macro */ %macro run_query(q,id); proc sql noprint; select count into: count from (&q.) a; quit; %mend; /* Some fake-data */ DATA queries; INPUT id :$12. query :$3000.; INFORMAT id $12.; INFILE DATALINES DSD; DATALINES; 01,SELECT COUNT(*) AS count FROM sashelp

How to use select statement in a value statement

房东的猫 提交于 2019-12-25 02:57:31
问题 I'm not sure what's wrong with my code. The log is saying that the select has a syntax error which I copied below. How do I fix this? "Syntax error, expecting one of the following: a quoted string, a numeric constant,a datetime constant, a missing value, +, -, MISSING, NULL, USER. ERROR: Syntax error, statement will be ignored." proc sql; insert into orion.test (Fruits, Vegetables, Drinks, Meats) values (select a.fruit, a.veggie, a.drink, a.meat FROM work.meals AS a); quit; 回答1: This should

Proc SQL, Aggregate of calculated value

别说谁变了你拦得住时间么 提交于 2019-12-24 12:24:48
问题 My current query is as follows: create table Report as select distinct a.Var1, count(distinct b.Var2) as Var2, from tbl1 a inner join tbl2 b on a.Var3=b.Var3 and a.Var4=b.Var4 inner join tbl3 c on c.Var3=b.Var3 group by a.Var1 order by Var2 desc ; This works fine and I get the following result Var1-----------------------------------------------Var2------------------------------------------------------------------------ COCA COLA ZERO CAN 8X330ML-----19279--------------------------------------

Which statistics is calculated faster in SAS, proc summary?

南楼画角 提交于 2019-12-23 10:15:12
问题 I need a theoretical answer. Imagine that you have a table with 1.5 billion rows (the table is created as column-based with DB2-Blu). You are using SAS and you will do some statistics by using Proc Summary like min/max/mean values, standard deviation value and percentile-10, percentile-90 through your peer-groups. For instance, you have 30.000 peer-groups and you have 50.000 values in each peer group (Total 1.5 billions values). The other case you have 3 million peer-groups and also you have

SAS - What is the SQL language used in a PROC SQL?

巧了我就是萌 提交于 2019-12-23 01:35:40
问题 I'm new to SAS and I'm using the PROC SQL functionality. I can not understand which is the sql language used in the PROC SQL. It seems similar to Oracle-Sql but some functions are not available. Can anyone clarify this point? 回答1: PROC SQL supports the ANSI SQL definition from 1992. You can also use most SAS functions. International Organization for Standardization (ISO): Database SQL. Document ISO/IEC 9075:1992. Also, as American National Standards Institute (ANSI) Document ANSI X3.135-1992

Dropping a table in SAS

末鹿安然 提交于 2019-12-21 07:34:18
问题 What is the most efficient way to drop a table in SAS? I have a program that loops and drops a large number of tables, and would like to know if there is a performance difference between PROC SQL; and PROC DATASETS; for dropping a single table at a time.. Or if there is another way perhaps??? 回答1: If it is reasonable to outsource to the OS, that might be fastest. Otherwise, my unscientific observations seem to suggest that drop table in proc sql is fastest. This surprised me as I expected

proc transpose with duplicate ID values

北战南征 提交于 2019-12-20 07:27:29
问题 I need help with proc transpose procedure in SAS. My code initially was: proc transpose data=temp out=temp1; by patid; var text; Id datanumber; run; This gave me error "The ID value " " occurs twice in the same BY group". I modified the code to this: proc sort data = temp; by patid text datanumber; run; data temp; set temp by patid text datanumber; if first.datanunmber then n = 0; n+1; run; proc sort data = temp; by patid text datanumber n; run; proc transpose out=temp1 (drop=n) let; by patid

Querying using the datepart from a time stamp in a pass-through Proc SQL

笑着哭i 提交于 2019-12-13 11:36:27
问题 I am trying to use the date part of a time-stamp in my where query in a db2 pass-through proc SQL code below. I tried using date and datepart functions but it wont work with this format. Does anyone know the name of the function to use in the same code below? PROC SQL; connect to db2(ssid=smtng); select * from connection to db2 (select * from ATable where DATEPART(timestamp) > '12/01/2013' FOR READ ONLY WITH UR ); DISCONNECT FROM DB2; QUIT; 回答1: If you use a function on the datetime field in

SQL counting days with gap / overlapping

爱⌒轻易说出口 提交于 2019-12-11 15:52:47
问题 I am working on a "counting days" problem almost identical to this one. I have a list of date(s), and need to count how many days used excluding duplicate, and handling the gaps. Same input and output. From: Markus Jarderot Input ID d1 d2 1 2011-08-01 2011-08-08 1 2011-08-02 2011-08-06 1 2011-08-03 2011-08-10 1 2011-08-12 2011-08-14 2 2011-08-01 2011-08-03 2 2011-08-02 2011-08-06 2 2011-08-05 2011-08-09 Output ID hold_days 1 11 2 8 SQL to find time elapsed from multiple overlapping intervals

SAS PROC SQL - Concatenate variable values into a single value by group

南楼画角 提交于 2019-12-11 14:49:01
问题 I have a data set which contains 'factor' values and corresponding 'response' values: data inTable; input fact $ val $; datalines; a 1 a 2 a 3 b 4 b 5 b 6 c 7 d 8 e 9 e 10 f 11 ; run; I want to aggregate response options by factor, i.e. I need to get I know perfectly well how to implement this in a data step running a loop through values and applying CATX (posted here). But can I do the same with PROC SQL, using a combination of GROUP BY and some character analog of SUM() or CATX()? Thanks