I am trying to combine site and patient with a hyphen in between the two variables, using the catx function. When I run this below, it ONLY gives me these three variables in my data, with no observations....any help is appreciated
data pat_info;
length site pt $ 15;
label pt_id='Site-Patient';
pt_id = catx('-',site,pt);
run;
So if you add the code to data step as follows, do you still have an issue?
data pat_info;
merge demog study;
by site pt;
label pt_id='Site-Patient';
pt_id = catx('-',site,pt);
run;
I don't see any kind of set statement or any other source of data.
You're running that code on nothing.
Sorry, this is my full code....I am running it after merging two data sets
proc format;
value sex
1=Female
2=Male
;
value race
1=Asian
2=Black
3=Caucasian
4=Other
;
run;
data study;
infile '/courses/dc4508e5ba27fe300/c_629/suppTRP-1062.txt' dlm=',' missover;
informat Site $1. Pt $2. Dosedate mmddyy10.;
input Site Pt Sex Race Dosedate Height Weight Result1 Result2 Result3;
if '01JAN1997'd <= dosedate <= '31DEC1997'd then doselot='S0576';
else if '31DEC1997'd < dosedate <= '10JAN1998'd then doselot='P1122';
else if dosedate > '10JAN1998'd then doselot='P0526';
if doselot='P0526' then do;
prot_amend='B';
if sex=1 then limit=0.03;
else if sex=2 then limit=0.02;
end;
else if doselot = 'S0576' or doselot='P1122' then do;
prot_amend='A';
limit=0.02;
end;
length site_name $30;
select(site);
when ('J') site_name='Aurora Health Associates';
when ('Q') site_name='Omaha Medical Center';
when ('R') site_name='Sherwin Heights Healthcare';
otherwise;
end;
format sex sex. race race. dosedate date.;
label site='Study Site'
pt='Patient'
dosedate='Dose Date'
doselot='Dose Lot'
prot_amend='Protocol Amendment'
limit='Lower Limit of Detection'
site_name='Site Name';
run;
libname demog '/courses/dc4508e5ba27fe300/c_629/saslib' access=readonly;
proc sort data=demog.demog1062 out=demog;
by site pt;
run;
proc sort data=study;
by site pt;
run;
data pat_info;
merge demog study;
by site pt;
run;
So if you add the code to data step as follows, do you still have an issue?
data pat_info;
merge demog study;
by site pt;
label pt_id='Site-Patient';
pt_id = catx('-',site,pt);
run;
No, that fixed it. Thank you. I needed it in the statement. I didnt want to put a set statement because I wanted it in the same data set, but putting that in the data step worked. Thanks!
You're welcome.
You can do it while merging:
data pat_info;
merge demog study;
by site pt;
length site_pt $15;
site_pt = catx('-',site,pt);
run;
You are creating variables but not populating them, so the output dataset has no rows/data. You need to either read in the data from another dataset with a set statement, or you need to generate data in your data step. Here's your code with one row of data created in the data step:
data pat_info;
length site pt $ 15;
label pt_id='Site-Patient';
Site='Mysite';
Pt='Patname';
pt_id = catx('-',site,pt);
run;
You have no statement that reads data into the data step. Either use a set statement to name an existing dataset that contains site and pt, or use infile and input to read data from an external file.
1) you miss input file/dataset
2) if you want to save memory variables add output statement.
3) you didn not assign value - neither to site nor to pt variables.
4) LABEL does not assine value to a variable but to the colomn header.
check next example:
data want;
site = 'New-York';
pt = 123;
lablel site_pt = 'New Var';
site_pt = catx('-',site,pt);
output;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.