BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

Hello, I tried a simple task to merge two datasets in SAS Studio. One data set is the clinic admittance data (21 observations) in the built-in SASUSER library with SAS BASE. The other data set was created by me (3 observations). I created following to do a simple demonstration of merging to students. It worked well in SAS BASE, but when run in SAS Studio, it generated output as attached. I found two odd things about the output: 1) instead of merging, it's more like SETting the two data sets; 2) actlevel in the created admitDiscount data set has value High printed as Hig. This stays unchanged even with a LENGTH statement before the INPUT in the data step. Any clue and/or suggestions? 

 

Thank you in advance. 

 

data admitDiscount;
input actlevel $ DisRate;
datalines;
HIGH 0.85
MOD 0.95
LOW 1.0
;
proc sort data = admit; by actlevel;
proc sort data = admitDiscount; by actlevel; run; 
data admit2;
merge admit admitDis;
by actlevel;
newfee = fee*DisRate;
format newfee 5.2;
run;
proc print; run;

 

Image0.png

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are you sure that is the data step you used to create the first three observations in that photograph?

data admitDiscount;
  input actlevel $ DisRate;
datalines;
HIGH 0.85
MOD 0.95
LOW 1.0
;

Because that data step would NOT truncate the strings to just the first three characters like your printout is showing.

Perhaps the variable the  ACTLEVEL in the ADMIT dataset is defined to be only 4 characters long.

And perhaps you did something silly like inserting TAB characters into the beginning of each line of the data when you ran your data step to create ADMITDISCOUNT.

The extra tab would explain why they did not match.  The length of 4 characters would explain why HIGH printed as HIG.  And the fact that the ASCII code for a tab is '09'x comes before any of H, M or L when sorting would explain why the three extra observations appeared first.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Are you sure that is the data step you used to create the first three observations in that photograph?

data admitDiscount;
  input actlevel $ DisRate;
datalines;
HIGH 0.85
MOD 0.95
LOW 1.0
;

Because that data step would NOT truncate the strings to just the first three characters like your printout is showing.

Perhaps the variable the  ACTLEVEL in the ADMIT dataset is defined to be only 4 characters long.

And perhaps you did something silly like inserting TAB characters into the beginning of each line of the data when you ran your data step to create ADMITDISCOUNT.

The extra tab would explain why they did not match.  The length of 4 characters would explain why HIGH printed as HIG.  And the fact that the ASCII code for a tab is '09'x comes before any of H, M or L when sorting would explain why the three extra observations appeared first.

Xin
Fluorite | Level 6 Xin
Fluorite | Level 6
It's the TAB!!! Thanks for the explanation. The problem fixed. Thank you!!!
Xin
Fluorite | Level 6 Xin
Fluorite | Level 6
Do you have document or link to share to read more about TAB in SAS Studio programmer and SAS BASE environment? Thanks.
Tom
Super User Tom
Super User

@Xin wrote:
Do you have document or link to share to read more about TAB in SAS Studio programmer and SAS BASE environment? Thanks.

Do not insert TAB characters into program files and your will not have these problems.

TAB characters do not belong in program files.

 

Instead in SAS/Studio you can change the preferences to replace tab characters with the spaces needed to move to the next tab stop.  Check the option labeled "Substitute spaces for tabs"

 

Tom_0-1669059317783.png

Tom
Super User Tom
Super User

Also do not indent lines of data.  Do yourself a favor and remember to also not indent the DATALINES; (aka CARDS;) statement that starts the block of data lines because the editor has a nasty habit of automatically indenting the next line to match the indent of the line before it.

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!

How to Concatenate Values

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.

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
  • 5 replies
  • 348 views
  • 0 likes
  • 2 in conversation