BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Linlin
Lapis Lazuli | Level 10

Dear All,

How should I get what I want?

Thank you very much for your input!

data have;
input (a b c) ($);
cards;
dd ee ff
ff hh gg
ss dd hh
;

observations in the dataset I want:

dd
ee
ff
hh
gg
ss

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Hi Linlin,

Use a variable list a--c to refer to your 100 variables (assuming they are listed consecutively) :

data have;
input (a b c) ($);
cards;
dd ee ff
ff hh gg
ss dd hh
;
data list;
set have;
array _a{*} a--c;
do i = 1 to dim(_a);
     value = _a{i};
     output;
     end;
run;

proc sql;
create table uniqueValues as
select unique value from list;
select * from uniqueValues;
quit;

PG

PG

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Rotate the data into a single column and let proc sort/FREQ/SQL find the distinct values.

data middle / view=middle;

  set have;

  array _all a b c;

  do over _all;  value = _all; output; end;

run;

proc freq data=middle ;

  tables value / out=want missing;

run;

Haikuo
Onyx | Level 15

Or Hash():

data have;

input (a b c) ($);

cards;

dd ee ff

ff hh gg

ss dd hh

;

data _null_;

  if _n_=1 then do;

  declare hash h();

h.definekey('newvar');

h.definedata('newvar');

h.definedone();

  end;

  set have end=last;

  array t _character_;

  length newvar $ 8;

call missing(newvar);

do over t;

rc=h.replace(key:t, data:t);

end;

if last then rc=h.output(dataset:'want');

run;

Haikuo

PGStats
Opal | Level 21

Hi Linlin,

Use a variable list a--c to refer to your 100 variables (assuming they are listed consecutively) :

data have;
input (a b c) ($);
cards;
dd ee ff
ff hh gg
ss dd hh
;
data list;
set have;
array _a{*} a--c;
do i = 1 to dim(_a);
     value = _a{i};
     output;
     end;
run;

proc sql;
create table uniqueValues as
select unique value from list;
select * from uniqueValues;
quit;

PG

PG
Linlin
Lapis Lazuli | Level 10

Hi Tom, Haikuo, and PG:

Thank you very much for your helpSmiley HappySmiley HappySmiley Happy!!! - Linlin

sandyming
Calcite | Level 5

Wow, three excellent ways to solve the problem!

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
  • 5 replies
  • 1410 views
  • 9 likes
  • 5 in conversation