Hi,
I am trying to create a dummy dataset for below data and I have provided my code as well. I have 20 records in my desired dataset but I am getting only 8 records when try to create dummy same like that. I am unable to create it by groups. Can you help me with this where I am doing wrong?
data have;
input AAGEGR1 $1-23 TEXT $24-40 TEXT1 $41-89 TEXT2 $90-126 TEXT3 $127-150;
datalines;
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink Any Unpleasant After Taste No
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink Any Unpleasant After Taste Yes
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] 1
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] 2
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] 3
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] 4
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] 5
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] Composite Evaluation [a]
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] OK or Better (>=3)
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Other Oral Meds [2] Worse than OK (<3)
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] 1
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] 2
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] 3
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] 4
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] 5
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] Composite Evaluation [a]
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] OK or Better (>=3)
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink How Easy to Take Study Drug [2] Worse than OK (<3)
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink Swallow the Dose No
Age group: 12-17 years First Assessment Mini-Tablets Crushed and Added to Food and Drink Swallow the Dose Yes
;
run;
data want;
do aagegr1n=1;
do textn=1;
do text1n=1;
do text2n=1,2,3,4;
do text3n=1,2;
output;
end;
end;
end;
end;
end;
run;
Below is the desired dataset:
data want;
input AAGEGR1n TEXTn TEXT1n TEXT2n TEXT3n;
datalines;
1 1 1 1 1
1 1 1 1 0
1 1 1 2 1
1 1 1 2 2
1 1 1 2 3
1 1 1 2 4
1 1 1 2 5
1 1 1 2 6
1 1 1 2 7
1 1 1 2 8
1 1 1 3 1
1 1 1 3 2
1 1 1 3 3
1 1 1 3 4
1 1 1 3 5
1 1 1 3 6
1 1 1 3 7
1 1 1 3 8
1 1 1 4 1
1 1 1 4 0
;
;
run;
Thanks,
Chinna
Could you please provide a quick sample of a few records of the desired output (want)?
@chinna0369 wrote:
data want;
input AAGEGR1n TEXTn TEXT1n TEXT2n TEXT3n;
datalines;
1 1 1 1 1 <= Does this 1 mean the same
1 1 1 1 0
1 1 1 2 1 <=As this 1? In your text data, the text for the first 1 is 'No' but for the third line here is a digit 1.
31 1 1 2 2
1 1 1 2 3
1 1 1 2 4
1 1 1 2 5
1 1 1 2 6
1 1 1 2 7
1 1 1 2 8
1 1 1 3 1
1 1 1 3 2
1 1 1 3 3
1 1 1 3 4
1 1 1 3 5
1 1 1 3 6
1 1 1 3 7
1 1 1 3 8
1 1 1 4 1
1 1 1 4 0
;
;
run;
To get your "code" you should consider the meaning of the characters...Regardless your, original Text3 has 10 different values. This coding only has 9.
BTW, it is much more common to see 1 for Yes and 0 for No (or True/False).
I'm not quite sure what this is useful for but if this Want data set is supposed to have a "structure" similar to the Have you do not have as many values of Text3n in Want as there are values of Text3 in the have data set.
Note: When I run your code a written it does not produce what I think you expect for a result because there are
some TAB characters and the resulting column counts don't quite match that input statement. After replacing the tabs...
Your Have data set has 10 different values for Text3. If you are trying to simulate that you need more values of Text3n. HOWEVER, of the Text2 values "Any Unpleasant After Taste" and "Swallow the Dose" are only associated with the 'Yes' and 'No' of Text3, and the "How Easy to Take Other Oral Meds [2]" and "How Easy to Take Study Drug [2]" are associated with the other 8 values of Text3.
Which means, if I understand what you want, something more like: (ugly intends because I'm too lazy to clean up the different TAB treatment of the forum software vs my editor settings for this many indents)
data want; do aagegr1n=1; do textn=1; do text1n=1; do text2n=1,2,3,4; if text2n in (1,4) then do; do text3n= 1,2; output; end; end; else if text2n in (2,3) then do; do text3n= 3 to 10; output; end; end; end; end; end; end; run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: