BookmarkSubscribeRSS Feed
Krissy217
Calcite | Level 5

I am having a hard time stacking my data sets. I have created three data sets but, when I go to stack them vertically, one of the data sets gets dropped and only two of my data sets get stacked. Here is what I have for code:

 

DATA WORK.Contact_IA;

Set HypImpt.IowaResidents (rename= (ZipCd = ZipCdtoo
)
);
keep SSN Inits City StateCd ZipCd;

length inits $3.;
Inits = SUBSTR(Initials, 3, 2)||SUBSTR(Initials, 1, 1);

City = propcase(City);

StateCd = "IA";

ZipCd = PUT(ZipCdtoo, 5.);


LABEL SSN = "Social Security Number"
Inits = "Subject Initials"
City = "City"
StateCd = "State Code"
ZipCd = "Zip Code";

FORMAT StateCd $StateCd.;

run;

PROC SORT;
BY SSN;
RUN;

proc contents data = work.contact_ia;
run;

proc print data = work.contact_ia;
run;

 

 

 

* Creating data for Mississippi *;
DATA WORK.Contact_MS;
set hypimpt.ms_citizens (rename = (SocSecNum = SSN))
;

inits = substr(Firstinit,1,1) || substr(middleinit, 1,1) ||substr(lastinit, 1,1);
StateCd= 'MS';
City = SCAN(CityState, 1, ',');

keep ssn inits StateCd City Zipcd;
label SSN = 'Social Security Number'
Inits = "Subject Initials"
City = 'City'
StateCd= 'State Code'
ZipCd = 'Zip Code';

format StateCd $StateCd.;
run;

Proc sort data = work.contact_MS;
by SSN;
run;

proc contents data = hypimpt.ms_citizens ;
run;

proc print data = hypimpt.ms_citizens;
run;

 

* Creating data for Utah *;
DATA WORK.Contact_UT;
retain SSN Inits City StateCd ZipCd;
set hypimpt.ut_records (rename = (inits= inits2
Zipcode= ZipCd));

SSNold = put(id, z9.);

part1 = substr(SSNold, 1, 3);
part2 = substr(SSNold, 4, 2);
part3 = substr(SSNold, 6, 4);
length SSN $11.;
SSN = Catx('-', part1, part2, part3);

length inits $3.;
inits = tranwrd(compress(inits2, '.'), ' ', '-');

City = scan(Cityst, 1, ',');
StateCd = 'UT';

KEEP SSN Inits City StateCd ZipCd;

LABEL SSN = "Social Security Number"
Inits = "Subject Initials"
City = "City"
StateCd = "State Code"
ZipCd = "Zip Code";
FORMAT StateCd $StateCd.;
RUN;

PROC SORT;
BY SSN;
RUN;


* Creating Combined Data Set *;
DATA HypTabs.Contact;

SET WORK.Contact_IA
WORK.Contact_MS
WORK.Contact_UT;

run;

3 REPLIES 3
SASKiwi
PROC Star

There is nothing syntactically wrong with your DATA step combining the three datasets. Please post the SAS log for that step so we can see what is going on.

Kurt_Bremser
Super User

Submit your code step by step, starting at the top. After each step, check the log, and only proceed to the next step once you have no ERRORs, WARNINGs, and no NOTEs beyond those that summarize the time taken, the observations read, and the observations and variables written. We call this a "clean log", see Maxim 25.

 

The last problem in the log is always the least important, fixing the first problem from the top down usually cleans up most, if not all, of the others.

 

Whenever you have issues fixing a single step, post the complete log from that step by copy/pasting it into a "code box" opened with the </> button.

ballardw
Super User

To much "work"

SSNold = put(id, z9.);

part1 = substr(SSNold, 1, 3);
part2 = substr(SSNold, 4, 2);
part3 = substr(SSNold, 6, 4);
length SSN $11.;
SSN = Catx('-', part1, part2, part3);

could be, if you really need a character SSN from numeric

ssn = put(ssnold,ssn.);

SAS supplies a format to display SSN with the dashes.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1719 views
  • 0 likes
  • 4 in conversation