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

I am using an array to create a variable I need - variable A.

When I do this, I need to keep certain variables B C D E F G, so I can have them in my final data file.

All of these are character vars except G (numeric var)

However, when I create this file with the array - these extra variables are repeating to fill in blanks - Since new variable A repeats for each ID. The missing in this file are okay. All I need is for the data from these extra variables to be in the first  row of the ID, not all of them. Could I add something to the array to make this happen? Or is there any other way I can do this after the data want is created? Thank you.


Data want (keep= ID A B C D E F G);
set have;
array _pres {*} pres: ;
do A=1 to dim(_pres);
if _pres{A}>0 then output;
end;
run;

What I am getting:

 

ID A         B             C          D                  E                  F            G

1  2    descript1       .           descript3      descript4          .          1

1  9    descript1        .          descript3      descript4          .          1

1  12  descript1       .           descript3      descript4         .           1

2  10    .                descript2     .             descript4    descript5    .

2   5    .                 descript2     .             descritp4    descript5    .

3   11  .                      .              descript3      .             .               .

3   20 .                      .              descript3      .             .                .

3   33 .                      .               descript3     .            .                 .

 

what I need:

 

ID A         B             C          D                  E                     F                 G

1  2    descript1       .           descript3      descript4          .                   1

1  9    .                    .                      .             .                    .                   .

1  12 .                      .                    .              .                    .                    .

2  10     .                descript2        .             descript4    descript5          .

2   5     .                      .                     .             .                         .            .

3   11   .                      .              descript3      .             .               .         .

3   20   .                   .                    .                .              .             .          .

3   33   .                    .                    .               .             .              .          .

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Data want (keep= ID A B C D E F G);
set have;
by ID;

if not first.id then call missing(B, C, D, E, F, G);

run;

View solution in original post

5 REPLIES 5
Reeza
Super User
Data want (keep= ID A B C D E F G);
set have;
by ID;

if not first.id then call missing(B, C, D, E, F, G);

run;
PaigeMiller
Diamond | Level 26

Try this:

 

Data want (keep= ID A B C D E F G);
set have;
by id;
if not first.id then call missing(b,c,d,e,f);
run;

If that's not it, then please provide your original data (in your data set named HAVE) as SAS data step code (instructions). 

--
Paige Miller
Mscarboncopy
Pyrite | Level 9

Thank you. That is it.

 

Reeza
Super User
Post the code and log.
Mscarboncopy
Pyrite | Level 9

Sorry. I got the error because I didn't add the commas. I meant to edit my answer but it took awhile to get through. Thank you!

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 5 replies
  • 2287 views
  • 2 likes
  • 3 in conversation