BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I would like to merge two datasets called report.FY08_datanodup and report.melig. The problem is that they are not in the same format. I attempted to correct the melig file for PAT_MAR to be numeric instead of character. it isn't working, please help. Thanks.

data one;
set report.melig;
newmar = 1*PAT_MAR;
run;
proc sort data = report.FY08_datanodup;
by PAT_ID;
run;



proc sort data = report.melig;
by PAT_ID;
run;
4 REPLIES 4
garybald
Calcite | Level 5
Convert to a numeric with the input fuction:

newmar = input(PAT_MAR,10.);

or

You can also convert to a character with the put function:

x = put(num_var, $10.);
Flip
Fluorite | Level 6
Why are you sorting report.melig after you create one with the new numeric variable?
deleted_user
Not applicable
Thanks for your help. I am attempting to merge two files report.Fiscal08_datanodup and report.melig, but the variable PAT_MAR is numeric in one and character in the latter file.

Anyway I attempted to do the following, but the log said

data report.six;
48 merge one report.melig;
ERROR: Variable PAT_MAR has been defined as both character and numeric.
49 by PAT_ID;
50 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set REPORT.SIX may be incomplete. When this step was stopped there were 0
observations and 91 variables.
WARNING: Data set REPORT.SIX was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.00 seconds


Rabiya

Please help.

data one;
set report.Fiscal08_datanodup;
x = put(num_var, $10.);
run;
proc sort data = one;
by PAT_ID;
run;


proc sort data = report.melig;
by PAT_ID;
run;
data report.six;
merge one report.melig;
by PAT_ID;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Your SAS variables listed in the BY statement must be of a consistent type, either NUMERIC or CHARACTER, and each of your input file specified on the MERGE statement must be sorted in the same sequence as listed in the BY list (in a typical scenario). Since you cannot have one variable with two different types, you are faced with doing a variable DROP and a RENAME process, so that you get back to having your BY variables all having the appropriate name.

So, one technical is to do the RENAME= on the SET for the file you want to modify, and then assign the same-named BY variable with the necessary ATTRIB (or LENGTH) attributes and derivation code, such as the INPUT function. After performing you data manipulation, verify the SAS variable results in each of your to-be-merged files using SAS PROC CONTENTS.

Once you have confirmed the SAS variable attributes are consistent, then move forward with your DATA step MERGE process.

The SAS support website http://support.sas.com/ hosts SAS product documentation and also additional user community (SGF and SUGI) technical papers as well as SAS-contributed technotes.

For example, I did a Google advanced search against the SAS.COM site - here is the argument entered:

data step merge processing site:sas.com


A SEARCH facility is also provided at the SAS support website, in addition to the Google example.

Here is a tech doc paper found from a search:

http://support.sas.com/techsup/technote/ts644.pdf

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 644 views
  • 0 likes
  • 4 in conversation