Help using Base SAS procedures

Using a catx statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Using a catx statement

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;


Accepted Solutions
Solution
‎02-22-2017 03:20 PM
PROC Star
Posts: 307

Re: Using a catx statement

Posted in reply to zjhansen30

 

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;

View solution in original post


All Replies
PROC Star
Posts: 307

Re: Using a catx statement

Posted in reply to zjhansen30

I don't see any kind of set statement or any other source of data.

 

You're running that code on nothing.

Occasional Contributor
Posts: 14

Re: Using a catx statement

Posted in reply to collinelliot

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;

Solution
‎02-22-2017 03:20 PM
PROC Star
Posts: 307

Re: Using a catx statement

Posted in reply to zjhansen30

 

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;

Occasional Contributor
Posts: 14

Re: Using a catx statement

Posted in reply to collinelliot

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!

PROC Star
Posts: 307

Re: Using a catx statement

Posted in reply to zjhansen30

You're welcome.

Super User
Posts: 7,771

Re: Using a catx statement

Posted in reply to zjhansen30

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 75

Re: Using a catx statement

Posted in reply to zjhansen30

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;
Super User
Posts: 7,771

Re: Using a catx statement

Posted in reply to zjhansen30

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,558

Re: Using a catx statement

Posted in reply to zjhansen30

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;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 341 views
  • 2 likes
  • 5 in conversation