11-30-2015 08:38 AM
I have a dataset and I need to show one column as both numeric and character. I added a simple dataset. Actually, I tried some methods and I created it but I'm not sure am I using the right method.What "library=sasuser" provides different form empty proc format.
data have; Length Column1 8 Column2 8; Infile Datalines missover dlm=","; Input Column1 Column2; datalines; 1,0 2,0 3,0 4,0 1,1 2,1 3,1 4,1 1,2 2,2 3,2 4,2 ; Run; proc format library=sasuser; value Column 0='G(1)' 1='G(2)' 2='G(3)'; run; proc format ; value Column 0='G(1)' 1='G(2)' 2='G(3)'; run; Proc sql; Create table Want As Select Column1 ,Column2 format=Column. From Have; Quit;
12-01-2015 10:20 AM
11-30-2015 09:13 AM
Your simplest solution would be to add this statement to your DATA step following the INPUT statement:
column3 = column2;
Then you could select column1 and column2 (with no formats) and column3 (with the format applied).
11-30-2015 10:34 AM - edited 11-30-2015 10:35 AM
You can't. A column can be either numeric or character. If you need to display both types of information, the default becomes character. If you need to show both the formatted and unformatted value of a variable, then you need two variables. One is the raw data and the second either has the variable with a format attached OR you can convert it to the character variable with the put function:
Proc sql; Create table Want As Select Column1, Column2, put(Column2, Column.) as Column3 label="Column2 Formatted" From Have; Quit;
11-30-2015 01:17 PM
I agree with @Reeza . Did you mean to ask if a column can be read into 2 different variables instead ?
12-01-2015 04:51 AM - edited 12-01-2015 04:52 AM
Thank you for the detailed information.
Actually, I need to make changes on Column2 variable. I don't want to make some changes on dataset and don't want new variable. I try to show variable as G(1), G(2) and G(3). I mean changes on view of variable.I'm not sure ,maybe I can overwrite the Column2 by using your method.
/*Method of Reeza*/
Proc sql; Create table Want As Select Column1,put(Column2, Column.) as Column2 label="Column2 Formatted" From Have; Quit;
12-01-2015 10:20 AM
12-01-2015 12:39 PM
12-01-2015 10:42 AM
Have you tried proc report?
proc report data=work.have;
columns Column1 Column2 Column2=Column2String;
define Column1 / display;
define Column2 / display;
define Column2String / display format=Column. "Column2";
12-10-2015 01:31 PM
I just wonder why it brings G(1) instead of G(1) THK when we use put function.I want to see space characters too. Have you got an idea ?
Need further help from the community? Please ask a new question.