Hello everyone,
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;
Thank you.
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).
Good luck.
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;
I agree with @Reeza . Did you mean to ask if a column can be read into 2 different variables instead ?
Hello @Reeza,
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;
Thank you.
Thank you @Reeza,
I think your reply is just I want. Thank your for the information.
I want to show data on dataset because I may use dataset to create another dataset but nice to know that, thank you @andreas_lds.
Thank you @kannand and @Astounding
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";
run;
Hello @Reeza,
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 ?
Thank you.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.