Hi I am trying to split a table into three tables with only one DATA step but what I am doing is not working. When I am outputting rows to these tables I need to create a variable called diet_type to display either Diet One Diet Two or Diet Three. This is my code for this entire dataset but I think the most relevant code is after the second data step.
options VALIDVARNAME=V7;
proc import datafile="/home/u54324957/The Files/Diet.csv" out=Diet
dbms=csv
replace;
data dietfile;
set Diet;
First_Name=PROPCASE(First_Name);
Last_Name=PROPCASE(Last_Name);
FullName=strip(Last_Name) || "," || strip(First_Name);
Length SexVariable $ 6;
if Sex=0 then
SexVariable="Male";
else if Sex=1 then
SexVariable="Female";
drop Sex;
rename SexVariable=Sex;
diet_num=input(substr(diet, 6, 1), 1.);
pre_weightlbs=pre_weight * 2.205;
format pre_weightlbs 5.1;
post_weightlbs=weight10weeks * 2.205;
format post_weightlbs 5.1;
weightloss=pre_weight - weight10weeks;
format weightloss 4.1;
drop Last_Name First_Name pre_weight Diet weight10weeks;
/* The most relevant code is below */
data Diet1 Diet2 Diet3;
set Diet;
if diet_num = 1 then do;
diet_num = 1;
output Diet1;
end;
else if diet_num=2 then do;
diet_num = 2;
output Diet2;
end;
else do;
diet_num = 3;
output Diet3;
end;
For some reason only Diet3 has any observations according to the Log.
diet_num is a numeric variable
Copy and paste this to get the data i.stack.imgur.com/8gVka.png. I think the only relevant column is diet_num.
Any ideas?
Do you want to split the dataset created by PROC IMPORT (diet) or the one you modified in your earlier data step (dietfile)?
Make sure that it knows you are done defining the data step by ending your data step with a RUN statement. If you are running interactively then SAS is still waiting for you to finish defining the data step before it can finish compiling it and start running it.
data Diet1 Diet2 Diet3;
set dietfile;
if diet_num = 1 then output Diet1;
else if diet_num=2 then output Diet2;
else output Diet3;
run;
Do you want to split the dataset created by PROC IMPORT (diet) or the one you modified in your earlier data step (dietfile)?
Make sure that it knows you are done defining the data step by ending your data step with a RUN statement. If you are running interactively then SAS is still waiting for you to finish defining the data step before it can finish compiling it and start running it.
data Diet1 Diet2 Diet3;
set dietfile;
if diet_num = 1 then output Diet1;
else if diet_num=2 then output Diet2;
else output Diet3;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.