- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello, i want create a vector of all options from vector of strings : i have to "multiply" every cell to other cell
example :
i have a variable of characters
a
b
d
e
i want to create the next variable
ab
ad
ae
bd
be
de
how i can do it?
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Normally in SAS you work an datasets not "vectors". So if we create your input as a single variable dataset.
data have ;
length letter $1 ;
input letter @@;
cards;
a b d e
;;;;
Then we can create your new single variable dataset from that using a DO loop and POINT= option on SET statement.
data want ;
length next_variable $2 ;
set have ;
do p=_n_+1 to nobs ;
set have (rename=(letter=next_letter)) nobs=nobs point=p ;
next_variable = cats(letter,next_letter);
output;
end;
keep next_variable ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This question seems to be for SQL.
Code: Program
data have ;
length letter $1 ;
input letter @@;
cards;
a b d e
;;;;
run;
proc sql;
create table want as
select cats(a.letter,b.letter) as new_letter
from have as a,have as b
where a.letter lt b.letter;
quit;
Xia Keshan
Message was edited by: xia keshan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Xie, agree thar SQL is a nice choice for this. But to comply withe requirement I think you need to change NE to GT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Opps. Thanks Linus. Code has been updated. I think ARRAY maybe is a better choice .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the actual data set is large, yes. But for normal data I think SQL is easier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But if there is not order out there, SQL would NOT work , Like something:
b
a
c
-->
ba
bc
ac
消息编辑者为:xia keshan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you want combination. Example straight out of SAS online documentation for LEXCOMB
array x[4] $3 ('a' 'b' 'd' 'e');
n=dim(x);
k=2;
ncomb=comb(n,k);
do j=1 to ncomb;
rc=lexcomb(j, k, of x
if rc<0 then leave;
end;
run;
1 a b rc=1
2 a d rc=2
3 a e rc=2
4 b d rc=1
5 b e rc=2
6 d e rc=1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you, that what i need. can you please the meaning of of x
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
x
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content