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

Hi,

Does anyone know a way to "fill out" a dataset with values from a second dataset using merge or set or other simple statements?  For example, I might have one dataset as:

letter num

a  .

b .

c .

And a second datset:

num

1

2

3

I need the resulting dataset to look like:

letter num

a 1

a 2

a 3

b 1

b 2

b 3

c 1

c 2

c 3

I really don't want to use an array.  Thanks for any ideas!

Jon

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select letter,set2.num

from set1,set2;

quit;

bharathtuppad
Obsidian | Level 7

proc sql;

create table ab as

select letter, coalesce(a.num, b.num)

from a,b;

select * from ab;

quit;

user24feb
Barite | Level 11

I really think the sql-version is an option here. But this might work as well, if the number of observations to fill out is fixed:


Data A;
  Input Letter $ @@;
  Call Missing (Num);
  Datalines;
  a b c
  ;
Run;

Data B;
  Input Num @@;
  Datalines;
  1 2 3
  ;
Run;

Data Want;
  Set A;
  By Letter;
  If First.Letter Then Do;
    i=0;
Set B Nobs=MaxNum;
    Do Until (i=MaxNum);
   i=i+1;
      Set B Point=i;
   Output;
    End;
  End;
Run;

Loko
Barite | Level 11

Hello,

data master;
input letter $ num;
datalines;
a  .
b .
c .
x .
y .
z .
;

data trans;
input num;
datalines;
1
2
3
;

data want;
do until(ltrans);
i+1;
set trans end=ltrans;
call symput('var'||put(i,1.), put(num, 1.));

end;

do until(lmaster);
j+1;
set master end=lmaster;
if mod(j,3)=1 then num=symget('var1');
else if mod(j,3)=2 then num=symget('var2');
else if mod(j,3)=0 then num=symget('var3');
output;
end;

stop;
drop i j;
run;

damanaulakh88
Obsidian | Level 7

1code.JPG

Output

2output.JPG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1583 views
  • 6 likes
  • 6 in conversation