data Example;
length Name $15;
input Name $;
if Name = 'Madhu' then do i = 1 to 5;
Designee = 'Jr_Associate';
Department = 'QA';
output;
end;
if Name = 'Sathwik' then do i = 1 to 5;
Designee = 'Jr_Associate';
Department = 'PB';
output;
end;
if Name = 'Mohan' then do i = 1 to 5;
Designee = 'Manager';
Department = 'PB';
output;
end;
if Name = 'Raja' then do i = 1 to 5;
Designee = 'Manager';
Department = 'QA';
output;
end;
if Name = 'Kiran' then do i = 1 to 5;
Designee = 'Manager';
Department = 'BA';
output;
end;
if Name = 'Sainath' then do i = 1 to 5;
Designee = 'Manager';
Department = 'CL';
output;
end;
drop i;
cards;
Madhu
Sathwik
Mohan
Raja
Kiran
Sainath
;
run;
Proc print data=Example;
run;
Move data out of code. Put the additional columns into the datalines and include them in the input statement.
Hello @sathwik,
Your question requires more details before experts can help. Can you revise your question to include more information?
Review this checklist:
To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message. From there you can adjust the title and add more details to the body of the message. Or, simply reply to this message with any additional information you can supply.
SAS experts are eager to help -- help them by providing as much detail as you can.
This prewritten response was triggered for you by fellow SAS Support Communities member @PeterClemmensen
.Please explain the issue you have with the code.
you are getting the zero observations because you are not using the exact string in the If statement
in the string, there are leading blanks which we need to keep for the code to work as below.
data Example;
length Name $15;
input Name $;
if Name = ' Madhu' then do i = 1 to 5;
Designee = 'Jr_Associate';
Department = 'QA';
output;
end;
if Name = ' Sathwik' then do i = 1 to 5;
Designee = 'Jr_Associate';
Department = 'PB';
output;
end;
if Name = ' Mohan' then do i = 1 to 5;
Designee = 'Manager';
Department = 'PB';
output;
end;
if Name = ' Raja' then do i = 1 to 5;
Designee = 'Manager';
Department = 'QA';
output;
end;
if Name = ' Kiran' then do i = 1 to 5;
Designee = 'Manager';
Department = 'BA';
output;
end;
if Name = ' Sainath' then do i = 1 to 5;
Designee = 'Manager';
Department = 'CL';
output;
end;
drop i;
cards;
Madhu
Sathwik
Mohan
Raja
Kiran
Sainath
;
run;
Proc print data=Example;
run;
Move data out of code. Put the additional columns into the datalines and include them in the input statement.
thank you all
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.