Hi All,
I want to use a proc SQL to create a column in my dataset like this
PROC SQL;
CREATE TABLE _DS AS
SELECT USUBJID,
CASE (PAR_1) WHEN (^= ' ') THEN END AS EOSREAS,
CASE (PAR_2) WHEN (^= ' ') THEN END AS EOTPREAS
FROM _DS1
ORDER BY USUBJID;
QUIT;
I would have done this if i am using data step:
if par_1 ^= ' ' then EOSREAS=PAR_1;
if par_2 ^= ' ' then EOTPREAS=Par_2;
Kindly advise
Rgds
proc sql;
create table _ds as
select
USUBJID,
case
when PAR_1 ^= ' '
then par_11
else ""
end as EOSREAS,
case
when PAR_2 ^= ' '
then par_7
else ""
end as EOTPREAS
from _ds1
order by USUBJID
;
quit;
Recommended reading: SQL Procedure's User Guide
PROC SQL;
CREATE TABLE _DS AS
SELECT USUBJID,
CASE WHEN (not missing(par_1)) THEN END AS EOSREAS,
CASE WHEN (not missing(par_2)) THEN END AS EOTPREAS
FROM _DS1
ORDER BY USUBJID;
QUIT;
Depending on your data structure a PROC TRANSPOSE or other approach may also be valid, since they can be dynamic and this is hardcoded remapping.
@chimukah wrote:
Hi All,
I want to use a proc SQL to create a column in my dataset like this
PROC SQL;
CREATE TABLE _DS AS
SELECT USUBJID,
CASE (PAR_1) WHEN (^= ' ') THEN END AS EOSREAS,
CASE (PAR_2) WHEN (^= ' ') THEN END AS EOTPREAS
FROM _DS1
ORDER BY USUBJID;
QUIT;
I would have done this if i am using data step:
if par_1 ^= ' ' then EOSREAS=PAR_1;
if par_2 ^= ' ' then EOTPREAS=Par_2;
Kindly advise
Rgds
Thanks for your suggestion.
Actually the par_1 & 2 variables were coming from transposed data.
However, implemented it yet errors as follows:
proc sql;
create table _ds as
select
USUBJID,
case
when PAR_1 ^= ' '
then par_11
else ""
end as EOSREAS,
case
when PAR_2 ^= ' '
then par_7
else ""
end as EOTPREAS
from _ds1
order by USUBJID
;
quit;
Recommended reading: SQL Procedure's User Guide
Thank you KurtBremser for your candid advice. It really helped.
Warm regard,
Chimukah
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.