sas macro for appending 24 tables [duplicate] - macros

This question already has answers here:
Merge multiple tables in sas using loop or macro
(2 answers)
Closed 7 years ago.
Hi I need help to append 24 sas tables. I would like to write a macro that appends 24 tables.
How do I create a do loop with the least amount of typing.
Thanks
proc sql;
create table master as
select * from table1
union all
select * from table2
union all
select * from table3;
quit;

I think you did not need a macro. Just type
data master;
set table1-table24;
run;

Related

How to use LIKE in these cases? [duplicate]

This question already has answers here:
Regular expression in PostgreSQL LIKE clause
(2 answers)
Closed 10 months ago.
There is a list of countries.
I want to get the list of the countries that:
consist of the letter U and A -or- S
consist of the letter U and any character except S.
These structures are correct for the MS SQL but don't work for Postgres
For MS SQL Server:
SELECT
country
FROM world.country
WHERE country LIKE 'U[AS]%'
SELECT
country
FROM world.country
WHERE country LIKE 'U[S]%'
For Postgres?
You can use SIMILAR TO Documentation
select * from (values ('UAA'),('MUA'),('UUA'),('USA')) as test (country)
where country SIMILAR TO 'U(A|S)%'
returns 'UAA' and 'USA'
You can use also POSIX regular expression with the same result.
select * from (values ('UAA'),('MUA'),('UUA'),('USA')) as test (country)
where country ~ '^U(A|S)'

postgreSQL: field separated by semicolon [duplicate]

This question already has answers here:
how to split a string in a column field value of a table to multiple rows in select query in postgresql
(1 answer)
Postgres split string with double quotes to multiple rows?
(1 answer)
regexp_split_to_table and row_number
(2 answers)
Closed 3 years ago.
I have a field called client_no_all:
client_no_all
14521;555555;636582142;
I want to separate the values and assign them to client_no:
client_no
14521
555555
636582142
Should I use a cursor to loop or pivot?
You can use following query.
The function string_to_array() splits a string by a delimiter into an array.
With the function unnest() you can expand an array to a set of rows.
SELECT unnest(string_to_array('1;2;3;4;5', ';')) AS val

Conditional expression, postgresql, get the result from the case [duplicate]

This question already has answers here:
Why can't I use column aliases in the next SELECT expression?
(4 answers)
Join Alias Columns SQL
(1 answer)
PostgreSQL does not accept column alias in WHERE clause
(1 answer)
Closed 4 years ago.
Looking at conditional expressions in Postgresql. To be more precise, this example.
SELECT * FROM test;
a
---
1
2
3
SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END AS amod
FROM test;
a | amod
---+-------
1 | one
2 | two
3 | other
I cant seem to find out how to now access the result under amod(one, two and other). After searching around, I haven't been able to find a way to solve it. Any pointers on how to do it?
EDIT: What I'm looking for is to be able to SELECT amod FROM the case expression and get it out as a table.

postgres `insert on conflict update` multiple columns [duplicate]

This question already has answers here:
How to update all columns with INSERT ... ON CONFLICT ...?
(2 answers)
Closed 4 years ago.
In this Postgres query,
INSERT INTO TB_PO
SELECT * FROM temporary_table
ON CONFLICT (id) DO UPDATE
SET id = excluded.id;
Since both the tables tb_po and temporary_table are identical with 26+ columns, is there a way I can specify after the SET, that it will set all columns of the affected row? So that I don't have to manually input each column with SET.
thanks
You could avoid some typing by generating your statement based on the results of
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'TB_PO';

EXISTS subquery: SELECT 1 or SELECT * FROM X performant in Postgres? [duplicate]

This question already has answers here:
What is easier to read in EXISTS subqueries? [closed]
(3 answers)
Closed 6 years ago.
Is it better (in terms of performance, speed, etc.) to write
SELECT * FROM a WHERE (EXISTS (SELECT * FROM b))
or
SELECT * FROM a WHERE (EXISTS (SELECT 1 FROM b))
in PostgreSQL?
p.s.
This question answers my question for MS SQL Server, but what about PostgreSQL?
Per the documentation:
Since the result depends only on whether any rows are returned, and
not on the contents of those rows, the output list of the subquery is
normally unimportant.