BookmarkSubscribeRSS Feed
d6k5d3
Pyrite | Level 9

Please have a look at the Dataset which is in Work library. I am working on this Dataset, I need to convert all these values in 12.5 numeric format. These variables are already in numeric format. What code to include after Data yyy; set zzz; ... to make the change? Much thanks.

 

 

Capture.PNG

6 REPLIES 6
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

please post the data is a SAS datastep.  It is hard to read a picture.

 

d6k5d3
Pyrite | Level 9
If you just click the picture, you would get the enlarged version.
andreas_lds
Jade | Level 19

Must repeat, what @VDD already requested: post the data as datastep using datalines-statement, so that we know what type the variables are. There is a huge difference between applying a format and converting data. And to suggest something for the later, we need something to work with. Another option for you: use the search-facility in the community. Converting text to numbers has been explained so many times, that you will, most likely, find adaptable code.

d6k5d3
Pyrite | Level 9
By the way, I just imported the data. And after importing, it looks like this. I want to make the changes in a data step.
ballardw
Super User

@d6k5d3 wrote:
By the way, I just imported the data. And after importing, it looks like this. I want to make the changes in a data step.

If you have an existing SAS data set you can change properties of variables in place with Proc DATASETS. You can rename variables, change formats, informats and labels.

 

a brief example creating a copy of a data set you should have:

Data work.class;
   set sashelp.class;
run;
proc datasets lib=work;
   modify class;
      format height f8.4
             weight f12.2
      ;
quit;  

the LIB on the  proc statement is the library the dataset(s) you want to modify are in.

 

The Modify statement indicates which dataset you are going to modify.

The format statement assigns the format to the variable. If you want to have the same format for multiple variables then

proc datasets lib=work;
   modify class;
      format height 
             weight best8.
      ;
quit; 

Informat or Label statements work the same. You can have another block of modify statements for another data set.

 

The QUIT is used to end the procedure because Datasets is one of the procedures that allows multiple Run groups.

d6k5d3
Pyrite | Level 9

 

@ballardw, thank you very much for the reply. I believe your code would work great. But a little change in the plan. I would import the data from a csv file, and all the figures you see would be in CHAR format.

 

So when I would go to modify the dataset, and format the variables to numeric, SAS would give me an error for trying to convert from CHAR to numeric.

 

What code would you suggest in the format line for conversion from CHAR to numeric?

 

I appreciate your time.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 5610 views
  • 3 likes
  • 4 in conversation