Weighted_amount:$1.;
the above line of code is for the formatting of the variable for replicating the dataset and not what I'm using in my script as part of the data step for computing and describing the variable " Weighted_amount"
If that is not what you used then why use that to provide that as example data???
That does not format. That is an instruction on how to read the data. It means "read the value into a character length one value". It makes the variable character.
So if I do not define the type of variable in the data step , will it default to character ?
SAS will default to NUMERIC with a BEST. format for values unless you provide instructions otherwise.
moreover after adding a line of code defining the format for Weighted_amount as a dollar numeric
That is done with a FORMAT statement, not INFORMAT or INPUT, which involve reading data. The Format you want is named DOLLARw.d such as Dollar16.2 to display upto 16 characters including a $ commas and decimal point with two decimal values.
data Report1a;
set Report1;
if Weightage > 0 then
Weighted_amount = Weightage*Unweighted_Amount ;
format Weighted_amount 7.2 ;
run;
but again it yields the same errors
How about the ERRORS associated with that data step? There would be an error similar to this. First code to create a small data set the way that you showed:
data junk;
input x :$1.;
datalines;
12345
;
data junk2;
set junk;
format x 7.2;
run;
And here is what the LOG of the second data step shows:
622 data junk2;
623 set junk;
624 format x 7.2;
---
230
ERROR 230-185: Invalid character format/informat decimal specified.
625 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JUNK2 may be incomplete. When this step was stopped there were 0
observations and 1 variables.
If you already have a data set this error means the previous data set was not replaced an you did nothing to change the property.
If a variable is character you cannot assign a numeric format to it. Period. You also cannot assign character formats to numeric values. Formats are for display an much match the variable type.
Unfortunately many people will use "format" from other languages in a different manner than SAS does and that can cause some confusion. Formats in SAS are in effect named display rules. I can have a custom format for a numeric values that would display a 1 (numeric one) as text "This is a one", or "Coded value for response choice: Eat Fish Daily" .
could you please you specify the exact line of code for delineating "Weighted_amount" as a numeric variable and the location ?
I don't think so. Your first data step has so many problems I don't what you expect. As others point out you are reading more values than are on your input lines and when I attempt your code the only thing read correctly (maybe) is Asset. If you are not going to READ your Unweighted_amount it does not belong on an INPUT statement. That is what INPUT does, reads data.
If this reads the shown line of data correctly, as it look at the data set or print, maybe:
data WORK.REPORT1;
infile datalines dsd truncover dlm=',';
input Category:$5. Level:$7. Sub_Level:$9. Description:$7. Weightage Unweighted_Amount;
format Weightage 15.2 ;
if Weightage > 0 then
Weighted_amount = Weightage*Unweighted_Amount;
datalines;
Asset,Level 1,Level 1 A,Sample1,1.00,2779
;;;;
I took out your label statement as it was duplicating the default label of the variable. Notice that I made some guesses as to where the character values end and used the comma as a delimiter between them with that indicated on the INFILE statement.
Reading spaces as part of the value is a somewhat tricky bit. Basically if you are going to use list input (the form of input statement you used) then delimiting the values is best. Otherwise you must make sure that the values start and end in specific columns for each variable and use one of the approaches to reading fixed column input, either column spedifications or fixed formats. But your datalines did not do that.
It is a good idea to place simple calculations and such in the same step that reads the data. Then you don't get into multiple data sets and getting confused about what comes from where.
... View more