BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dave
Calcite | Level 5

I imported a csv file with  a negative sign behind the number. SAS seems to have dropped the negative signs on numeric values that had it.

original format 1.79-;114-;116

output has 1.79 and 114 and 116

How do I import and keep the negative sign where it exists.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

    INPUT

        F1               : ?? BEST10.

        F2               : ?? BEST18.

        F3               : $CHAR6.

        F4               : $CHAR3.

        F5               : $CHAR1.

        F6               : ?? YYMMDD8.

        F7               : ?? DDMMYY6.

        F8               : $CHAR3.

        F9               : $CHAR3.

        F10              : $CHAR3.

        CAT              : ?? TRAILSGN.

        GAM              : ?? TRAILSGN.

        SAL              : ?? TRAILSGN. ;

RUN;

View solution in original post

10 REPLIES 10
data_null__
Jade | Level 19

I don't know if PROC IMPORT will handle this properly.  You can roll your own or modify the code that PROC IMPORT produces. 

The informat you need is TRAILSGN

353 data _null_;

354 infile cards dsd dlm=';';

355 input (a1-a3) (:TRAILSGN.);

356 put (_all_)(=);

357 cards4;

a1=-1.79 a2=-114 a3=116

Dave
Calcite | Level 5

Thanks. This is my first attempt at SAS so apologies for silly questions. I took your code and put it in the log file under INFORMAT. I changed (A1-A3) to match the names under informat that correspond to value cells. After I pasted it in, I clicked "Run" and it says Details and 1 of 2 running but it may be hanging? FYI, the code file does show a line across after Informat before the code I pasted.

Am I doing something wrong?

example:

data _null_;

infile cards dsd dlm=';';

input (CAT) (:TRAILSGN.);

input (GAM) (:TRAILSGN.);

input (SAL) (:TRAILSGN.);

put (_all_)(=);

cards4;

data_null__
Jade | Level 19

Like this....

data _null_;

   infile cards dsd dlm=';';

   input (cat gam sal) (:TRAILSGN.);

   put (_all_)(=);

   cards4;

1.79-;114-;116

;;;;

   run;

You will need to modify the code that reads YOUR data with the correct INFORMAT.

manojinpec
Obsidian | Level 7

Can you provide the log pls?

data_null__
Jade | Level 19

I think you need to show your code.  My code is only an example of the INFORMAT that you need to use.  You will need to include it in the code that you write to read the CSV file.

Dave
Calcite | Level 5

Yes, sorry for delay. I have not bothered yet to name all the variables for this since the last 3 variables or columns are are the only ones that I am having issues with. Thanks for taking the time to help. Here is a copy of the log:

/* --------------------------------------------------------------------

   Code generated by a SAS task

  

   Generated on Saturday, July 02, 2011 at 4:00:32 PM

   By task:     Import Data

  

   Source file: E:\David's Documents\Clients\Stats\Data\Data query - Run\reports\file1.CSV

   Server:      Local File System

  

   Output data: WORK.file1

   Server:      Local

   -------------------------------------------------------------------- */

DATA WORK.AA_HT1;

    LENGTH

        F1                 8

        F2                 8

        F3               $ 6

        F4               $ 3

        F5               $ 1

        F6                 8

        F7                 8

        F8               $ 3

        F9               $ 3

        F10              $ 3

        CAT                8

        GAM                8

        SAL                8 ;

    FORMAT

        F1               BEST10.

        F2               BEST18.

        F3               $CHAR6.

        F4               $CHAR3.

        F5               $CHAR1.

        F6               YYMMDD10.

        F7               DDMMYY10.

        F8               $CHAR3.

        F9               $CHAR3.

        F10              $CHAR3.

        CAT              BEST9.

        GAM              BEST10.

        SAL              BEST10. ;

    INFORMAT

        F1               BEST10.

        F2               BEST18.

        F3               $CHAR6.

        F4               $CHAR3.

        F5               $CHAR1.

        F6               YYMMDD10.

        F7               DDMMYY10.

        F8               $CHAR3.

        F9               $CHAR3.

        F10              $CHAR3.

        CAT              BEST9.

        GAM              BEST10.

        SAL              BEST10. ;

    INFILE 'C:\Users\David\AppData\Local\Temp\SEG1844\file1-bd5b8ded924346ca9b53f0e328e93c43.txt'

        LRECL=98

        ENCODING="WLATIN1"

        TERMSTR=CRLF

        DLM='7F'x

        MISSOVER

        DSD ;

    INPUT

        F1               : ?? BEST10.

        F2               : ?? BEST18.

        F3               : $CHAR6.

        F4               : $CHAR3.

        F5               : $CHAR1.

        F6               : ?? YYMMDD8.

        F7               : ?? DDMMYY6.

        F8               : $CHAR3.

        F9               : $CHAR3.

        F10              : $CHAR3.

        CAT              : ?? COMMA9.

        GAM              : ?? COMMA10.

        SAL              : ?? COMMA10. ;

RUN;

data_null__
Jade | Level 19

    INPUT

        F1               : ?? BEST10.

        F2               : ?? BEST18.

        F3               : $CHAR6.

        F4               : $CHAR3.

        F5               : $CHAR1.

        F6               : ?? YYMMDD8.

        F7               : ?? DDMMYY6.

        F8               : $CHAR3.

        F9               : $CHAR3.

        F10              : $CHAR3.

        CAT              : ?? TRAILSGN.

        GAM              : ?? TRAILSGN.

        SAL              : ?? TRAILSGN. ;

RUN;

Dave
Calcite | Level 5

Thanks!

Dave
Calcite | Level 5

Hi data_null. I may have some data manipulations and analysis to do. I am considering working with a consultant(s) and am making a few inquiries in case. I have added you as a friend so you can reply there if you wish. Thanks.

Ksharp
Super User

Hi. Dave

I have received your information.Can you send me some detail about your problem?

Thanks.

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 4601 views
  • 0 likes
  • 4 in conversation