Hi there- I am running this "simple" piece of code to isolate data based on a date variable.
See this VERY important log line:
informat " DATE"N yymmdd10. ;
Your CSV file obviously contains blank space in the header line, so PROC IMPORT dutifully uses a name literal (quotes and trailing N) to keep this in the variable name, which will now force you to do the same throughout your code, which is NOT GOOD AT ALL (unless you crave unnecessary extra work).
Submit
options validvarname=v7;
before running proc import, or (best option by far) copy the data step code from the log, fix it, and run that directly. Replace the blanks in variable names with underlines, so you can use the variables without name literals.
Please post the code of proc contents also.
In the set statement you are using electric.elec, but the error message complains about Date not being in ELECTRIC.SBSA_ELEC.
The log is not from the code you posted, as ELECTRIC.SBSA_ELEC is not used there.
When posting logs, ALWAYS include the complete code, and use this button to post it:
The "little running man" right next to it is for SAS code.
I tried this code as well
DATE2 = INPUT(PUT(DATE,8.),YYMMDD10.);
FORMAT DATE2 YYMMDD8.;
But all that does is create another DATE and DATE2 field- both empty and no errors in the log.
It is as if I am unable to reference the DATE field of the original dataset.
This code also did not work
my_date_char = put(DATE, 8.);
It creates anothe DATE filed as opposed to converting the existing DATE field to a character value.
Start at the beginning of your code. Inspect the first dataset which you use; take note of the type and other attributes there.
Then, once you have verified that date is a numeric variable with a date format attached and does have non-missing values (e.g. run PROC FREQ on the dataset), proceed down the path of your process; see if you have any NOTEs beyond those recording execution time and the number of observations and variables in newly created datasets.
If anything beyond this happens and puzzles you, post the log as described.
A "good" step has nothing in the log beyond the code, the execution time (and other execution stats), the numbers of observations in incoming and outgoing datasets, and the number of variables in a new dataset. ANY further NOTE points to a possible issue and must be dealt with.
The more details you provide, the easier it is for us to help you; therefore, always post complete codes and complete logs, so any message in the log is in the right context.
This is how I read in the data
proc import datafile= "/home/u44662193/Electricity/CMP5.FULLEXT.CSV"
dbms=dlm
out=electric.Elec
replace;
GETNAMES=YES;
delimiter=',';
guessingrows=10000;
run;
SAS assigned "DATE" as the first field correctly, and it is informant yymmdd10.
The CONTENTS Procedure
Data Set NameObservationsMember TypeVariablesEngineIndexesCreatedObservation LengthLast ModifiedDeleted ObservationsProtectionCompressedData Set TypeSortedLabel Data Representation Encoding
ELECTRIC.ELEC | 2862498 |
DATA | 8 |
V9 | 0 |
2022/03/09 11:46:22 | 80 |
2022/03/09 11:46:22 | 0 |
NO | |
NO | |
SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64 | |
utf-8 Unicode (UTF-8) |
Engine/Host Dependent InformationData Set Page SizeNumber of Data Set PagesFirst Data PageMax Obs per PageObs in First Data PageNumber of Data Set RepairsFilenameRelease CreatedHost CreatedInode NumberAccess PermissionOwner NameFile SizeFile Size (bytes)
131072 |
1751 |
1 |
1635 |
1599 |
0 |
/home/u44662193/elec.sas7bdat |
9.0401M6 |
Linux |
199361150 |
rw-r--r-- |
u44662193 |
219MB |
229638144 |
Alphabetic List of Variables and Attributes# Variable Type Len Format Informat13578462
DATE | Num | 8 | YYMMDD10. | YYMMDD10. |
ACC NUM | Num | 8 | BEST12. | BEST32. |
AMOUNT | Num | 8 | BEST12. | BEST32. |
DESCR | Char | 20 | $20. | $20. |
NARR | Char | 15 | $15. | $15. |
SER NO | Char | 1 | $1. | $1. |
STATEMENT CODE | Num | 8 | BEST12. | BEST32. |
TC | Num | 8 | BEST12. | BEST32. |
Running your proc freq to check the DATE field it says this:
proc freq data = electric.Elec;
tables Date;
run;
Please open your csv file with a text editor (not with Excel!) and copy/paste the first few lines into the code box (</> button).
Also, copy the import data step (which PROC IMPORT creates) from the log and post it into a code box.
@programeerSAS wrote:
Hi Kurt- I am using SAS studio via browser, no such option
These buttons are part of the SAS Community interface, not SAS Studio. In SAS Studio, switch to the Log tab, mark and copy the log text, then paste it into the appropriate window here as described.
See this VERY important log line:
informat " DATE"N yymmdd10. ;
Your CSV file obviously contains blank space in the header line, so PROC IMPORT dutifully uses a name literal (quotes and trailing N) to keep this in the variable name, which will now force you to do the same throughout your code, which is NOT GOOD AT ALL (unless you crave unnecessary extra work).
Submit
options validvarname=v7;
before running proc import, or (best option by far) copy the data step code from the log, fix it, and run that directly. Replace the blanks in variable names with underlines, so you can use the variables without name literals.
Kudos - that was certainly a piece of masterfully guiding the OP to provide the info you needed to identify the issue.
@Patrick wrote:
Kudos - that was certainly a piece of masterfully guiding the OP to provide the info you needed to identify the issue.
I had the same thought. Thanks, @Patrick, for expressing it.
This thread is also yet another example where complete listing output, posted into a code box, would have clarified things very early:
Alphabetic List of Variables and Attributes # Variable Type Len 1 DATE Num 8 2 ACC NUM Num 8 ...
Both the indentation of "DATE" and the seemingly non-alphabetic sort order -- neither of which could be seen in the partial HTML output shown in @programeerSAS's initial post -- would have revealed the cause of the issue.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.