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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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