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

How do I get the correct encoding for this data i am retrieving form with an api? The Danish letters æ,ø,å does not show corret

 

filename src temp encoding="utf-8";
proc http
     method="GET"
     url="%nrstr(https://dawa.aws.dk/adresser?q=Ærøgade&struktur=mini&per_side=1&format=csv)"
     out=src;
    run;
	data _null_;
	infile src;
	input;
	put _infile_;
	run;
	data test ;
	infile src encoding="utf-8" dlm=',' missover dsd firstobs=2 ;
	length id $ 36 status $1 vejkode $4 vejnavn $20 adresseringsvejnavn $20 husnr $10 etage $10 dor $10 supplerendebynavn $10 postnr $4 postnrnavn $20 kommunekode $4 adgangsadresseid $36 x 8 y 8 ;  
   input id $ status $ vejkode $ vejnavn $ adresseringsvejnavn $ husnr $ etage$ dor $ supplerendebynavn $ postnr $ postnrnavn $ kommunekode $ adgangsadresseid x y;
run;

Data example

id,status,vejkode,vejnavn,adresseringsvejnavn,husnr,etage,dør,supplerendebynavn,postnr,postnrnavn
,kommunekode,adgangsadresseid,x,y
0a3f50b3-135b-32b8-e044-0003ba298018,1,0365,Ærøgade,Ærøgade,2,,,,5960,Marstal,0492,0a3f5088-8b
75-32b8-e044-0003ba298018,10.51420646,54.85857924
1 ACCEPTED SOLUTION

Accepted Solutions
rudfaden
Pyrite | Level 9

I found a solution. Basically you save the file with utf-8 and then open it with wlatin.

 

filename resp "C:\Temp\map.json";
    filename minmap 'C:/Temp/gogle_distance.map';

    proc http
     url="https://maps.googleapis.com/maps/api/directions/json?origin=&home.%nrstr(&destination=)&work."
     method= "GET"
     out=resp;
    run;

    %** trick der gøre at JSON filen encodes med wlatin;
    filename resp "C:\Temp\map.json" encoding='utf-8';
    filename resp1 "C:\Temp\map1.json" encoding='wlatin1';

    data _null_;
      infile resp;
      file resp1;
      input;
      put _infile_;
    run;

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What is your SAS session encoding?  This is normally setup when SAS starts up, you would need to change it there.

rudfaden
Pyrite | Level 9

That is not possible. I need a solution where the encoding is converted to my sas encoding,

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't believe that is possible.  If your SAS session is Wlatin, and the data coming in has UTF-8 or 16, which both have far more characters in their sets, then "converting" data is not possible as the wlatin charset is too small to handle it.  This is what you are seeing now, where the character set just says I don't know and puts a strange symbol.

rudfaden
Pyrite | Level 9

I am not talking about converting the whole charset to from utf-8 to wlatin. Only those that are in wlatin

rudfaden
Pyrite | Level 9

I found a solution. Basically you save the file with utf-8 and then open it with wlatin.

 

filename resp "C:\Temp\map.json";
    filename minmap 'C:/Temp/gogle_distance.map';

    proc http
     url="https://maps.googleapis.com/maps/api/directions/json?origin=&home.%nrstr(&destination=)&work."
     method= "GET"
     out=resp;
    run;

    %** trick der gøre at JSON filen encodes med wlatin;
    filename resp "C:\Temp\map.json" encoding='utf-8';
    filename resp1 "C:\Temp\map1.json" encoding='wlatin1';

    data _null_;
      infile resp;
      file resp1;
      input;
      put _infile_;
    run;

 

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!

How to Concatenate Values

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.

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
  • 5 replies
  • 2341 views
  • 1 like
  • 2 in conversation