BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chimukah
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
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

View solution in original post

4 REPLIES 4
Reeza
Super User
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


 

 

chimukah
Obsidian | Level 7

Thanks for your suggestion.

 

Actually the par_1 & 2 variables were coming from transposed data.

However, implemented it yet errors as follows:

chimukah_0-1603813054282.png

 

Kurt_Bremser
Super User
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

chimukah
Obsidian | Level 7

Thank you KurtBremser for your candid advice. It really helped.

Warm regard,
Chimukah

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1213 views
  • 1 like
  • 3 in conversation