Can you be more clear please.
What is your starting dataset? Show it as a data step that recreates it.
Is it something like:
data have;
input a b $;
cards;
1 A
1 B
1 C
2 A
2 B
;
What is your desired output dataset? Is it something like this?
data want;
input a b_list :$20.;
cards;
1 A,B,C
2 A,B
;
If so then try:
data want;
length a 8 b_list $20 ;
do until(last.a);
set have;
by a;
b_list=catx(',',b_list,b);
end;
drop b;
run;
i want my desire input to be like
nO NAME TO NO NAME
1 A 1 A,B AND C
1 B 1 A,B AND C
1 C 1 A,B AND C
2 A 2 A AND B
2 B 2 A AND B
Thanks for the reply. I am new to SAS. Normally i'll just import data and SAS will auto generate the code but i cant find a way to solve this problem. Need help from all who know how to use it.
@Niz88 wrote:
i want my desire input to be like
nO NAME TO NO NAME 1 A 1 A,B AND C 1 B 1 A,B AND C 1 C 1 A,B AND C 2 A 2 A AND B 2 B 2 A AND B Thanks for the reply. I am new to SAS. Normally i'll just import data and SAS will auto generate the code but i cant find a way to solve this problem. Need help from all who know how to use it.
If you are dealing with Proc Import or wizard creating the data you have an issue in that the existing NAME variable is not going to be long enough to hold 3 (or more) values.
Do you actually want the word AND in the data? That adds a certain amount of complication to the possible solutions.
NO NAME TO NO NAME DATA
1 A 1 A,B,C
1 B 1 A,B,C
1 C 1 A,B,C
2 A 2 A,B
2 B 2 A,B
thanks ballardw for the reply. ok,then i remove the word AND.
I tried to use the advance expression to concatenate the data together but unable to do so. Will have to try tom code. I am trying to learn how to use the code.
What is an "advanced expression"?
You are you using some type of point and click code generator in Enterprise Guide?
Perhaps, borrowing from @Tom
The first data step is just to build something similar to what you describe as your data.
The data set TEMP is code you would run against that data set to get the value list. Depending on the actual lengths of your values the length of the list variable may need to be much larger. This sort of thing is not normally built by point and click interfaces because it is a non-standard action and makes data that is often much harder to work with for some tasks.
Then the last step combines the two data sets.
data have; input a b $; cards; 1 A 1 B 1 C 2 A 2 B ; data temp; length a 8 b_list $20 ; do until(last.a); set have; by a; b_list=catx(',',b_list,b); end; drop b; run; data want; merge have temp ; by a; run;
Still want to know what you expect to do with the combined values, especially when they are repeated.
@Niz88 wrote:
Can sas do this
A B to A B
1 A 1 A,B and C
1 B 1 A,B and C
1 C 1 A,B and C
2 A 2 A and B
2 B 2 A and B
There is not way in that stuff above to tell what the starting variables are or what the value per variable might be. SAS works on variables.
Please provide an of your existing data in the form of a data step.
And please describe what you will do with the resulting data set that can't be done with it in the current form.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.