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

Hello,

I have a sample dataset below.  Two questions; first, the ")" are missing in all the data lines, not sure how to fix it;  second, my Proc transpose codes are not working. Please help; thanks.

data Mean_Median_Output;
input House 1.0 LOS_Mean_Q1Q3 $ LOS_Median_range $ Age_Mean_Q1Q3 $ Age_Median_range $;
infile datalines delimiter='/';
datalines;
0/2.2 (1-2)/1.0 (0-92)/3.7 (2-4)/2.0 (2-17)/
1/2.9 (1-3)/2.0 (0-117)/6.6 (3-9)/5.0 (2-17)/
;
run;

Proc transpose data=Mean_Median_Output out=Mean_Median_transpose prefix=House_; run;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @ybz12003,

 

Use a LENGTH statement or informats (as shown in the example below) to specify sufficient lengths for your character variables. Just using the dollar sign in the INPUT statement means a default length of 8 bytes.

input House (LOS_Mean_Q1Q3 LOS_Median_range Age_Mean_Q1Q3 Age_Median_range) (:$13.);

I guess that you want to add these ID and VAR statements to your PROC TRANSPOSE step:

proc transpose data=Mean_Median_Output out=Mean_Median_transpose prefix=House_;
id house;
var _char_;
run;

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Variables defaults to 8 in lenght, specifying a length of 9 should fix the truncation problem.

 

What is your specific problem with PROC TRANSPOSE?

Data never sleeps
yabwon
Onyx | Level 15

For missing ")"  - set proper variable LENGTH:

data Mean_Median_Output;
LENGTH House 8 LOS_Mean_Q1Q3 LOS_Median_range Age_Mean_Q1Q3 Age_Median_range $ 30;
input House 1.0 LOS_Mean_Q1Q3 $ LOS_Median_range $ Age_Mean_Q1Q3 $ Age_Median_range $;
infile datalines delimiter='/';
datalines;
0/2.2 (1-2)/1.0 (0-92)/3.7 (2-4)/2.0 (2-17)/
1/2.9 (1-3)/2.0 (0-117)/6.6 (3-9)/5.0 (2-17)/
;
run;
proc print;
run;

For transpose - what output do you expect to get?

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



FreelanceReinh
Jade | Level 19

Hello @ybz12003,

 

Use a LENGTH statement or informats (as shown in the example below) to specify sufficient lengths for your character variables. Just using the dollar sign in the INPUT statement means a default length of 8 bytes.

input House (LOS_Mean_Q1Q3 LOS_Median_range Age_Mean_Q1Q3 Age_Median_range) (:$13.);

I guess that you want to add these ID and VAR statements to your PROC TRANSPOSE step:

proc transpose data=Mean_Median_Output out=Mean_Median_transpose prefix=House_;
id house;
var _char_;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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