Help using Base SAS procedures

proc expand question

Accepted Solution Solved
Reply
PROC Star
Posts: 7,484
Accepted Solution

proc expand question

Just out of curiosity, can someone post a proc expand solution to the problem posed in the thread:

TIA,

Art


Accepted Solutions
Solution
‎03-09-2015 10:46 PM
Respected Advisor
Posts: 4,927

Re: proc expand question

In this particular case, one must do a little gymnastics to fix the beginning and end of the series :

data temp(drop=i firstSmiley Happy first(keep=firstSmiley Happy;

set have end=done;

array v{*} v:;

array first{1024} (1024*.);

do i = 1 to dim(v);

    if v{i}=0 then call missing (v{i});

    else if missing(first{i}) then first{i} = v{i};

    end;

output temp;

if done then output first;

run;

proc expand data=temp out=expanded;

id id;

convert v: / method=join;

run;

data want;

if _n_=1 then set first;

set expanded;

array v{*} v:;

array first{*} first:;

do i = 1 to dim(v);

    if missing(v{i}) then

        if missing(first{i}) then v{i} = 0;

        else v{i} = first{i};

    else call missing(first{i});

    end;

drop i first:;

run;

PG

PG

View solution in original post


All Replies
Trusted Advisor
Posts: 1,301

Re: proc expand question

@art297,

I posted a PROC EXPAND example and another using PROC TRANSREG for good measure.

For further reading I would recommend the following topic from SAS-L:

http://marc.info/?t=139164201000004&r=1&w=2

Solution
‎03-09-2015 10:46 PM
Respected Advisor
Posts: 4,927

Re: proc expand question

In this particular case, one must do a little gymnastics to fix the beginning and end of the series :

data temp(drop=i firstSmiley Happy first(keep=firstSmiley Happy;

set have end=done;

array v{*} v:;

array first{1024} (1024*.);

do i = 1 to dim(v);

    if v{i}=0 then call missing (v{i});

    else if missing(first{i}) then first{i} = v{i};

    end;

output temp;

if done then output first;

run;

proc expand data=temp out=expanded;

id id;

convert v: / method=join;

run;

data want;

if _n_=1 then set first;

set expanded;

array v{*} v:;

array first{*} first:;

do i = 1 to dim(v);

    if missing(v{i}) then

        if missing(first{i}) then v{i} = 0;

        else v{i} = first{i};

    else call missing(first{i});

    end;

drop i first:;

run;

PG

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 187 views
  • 3 likes
  • 3 in conversation