BookmarkSubscribeRSS Feed
Markanti
Calcite | Level 5
  1. Use the code in the unfinished code section to create the data set call “two” from “one”, which you created in problem 1.  Add the following to “two”:
    1. Create a new text variable called “yrob2” using the last 2 digits of the variable “yrob”.  For example if year = 1980 we would want 80 for this new variable. 
    2. Next, create a new text variable called “last4” from SSN using the last 4 digits of the SSN.
    3. Now, create a new text variable called “ID” by concatenating “clinic”, “mthob”, “yrob2” & “last4” (in this order). 
    4. Remove any spaces or blanks from this new variable called “ID”. 
    5. Remove all variables from this dataset except for name & ID. Hint: Think about the most efficient way to do this.

finished Code

*Lab 8 – Problem 2;

title "Building an ID number from data";

data lab.ssn_number;
set lab.one;
ssn2 = compress(ssn, '-');
ssn3 = input(ssn2, ??11.);
drop ssn2;
run;

proc print data=lab.ssn_number;
run;

2 REPLIES 2
Patrick
Opal | Level 21

The code you shared doesn't have much to do with solving problems 1 to 5. 

To support homework forum members normally want to see some of your own effort and then help with the bits where you get really stuck after you first tried yourself. 

ballardw
Super User

Hint: When you have text values with a delimiter such as - that usually appears in SSN then SCAN is useful tool to get the nth element of the value

 

Hint2: NEVER input parts of character values to numeric if the instruction is to Concatenate. You will lose leading zeroes and add complication to the code for concatenating.

 

Personally I consider #3 to be dangerous in terms of actual use. Discuss this with your instructor.

Suppose you have two values before removing blanks that look like this (because you created a numeric value from SSN of 0078 that becomes 78 for example)

 

 

' 1 2 12 5678'
'12 12 56 78'

If you remove blanks you get

'12125678'
'12125678'

Unless your codes for things like Clinic and your month always uses 2 digits (and years REALLY should use 4 digits, look up Y2K) you have a possibility of creating duplicate values that should mean different things. Of course I do not have any of your data to see how likely this is but is something to be aware of.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 540 views
  • 1 like
  • 3 in conversation